Posts Tagged ‘powershell’

Let’s take this scenario. You’ve uploaded a new version of software to the Server. You didn’t push the “Unblock” putton in file Properties… . The application upgraded itself, and for now you’ve a thousands of files in hundreds of folders which are “Blocked”, but can be readable… how can you repair this? With PowerShell 3!

dir c:\mydir -Recurse | Unblock-File


dir c:\mydir -Recurse | Unblock-File -WhatIf

Easy, huh?

You have more than 500-1000 users and need to change the UserPrincipalName?


Get-ADUser -Filter * -SearchBase $ou | ForEach-Object { $newUpn = $_.UserPrincipalName.Replace($old,$new) $_ | Set-ADUser -server $server -UserPrincipalName $newUpn }

Of course it is better to debug the command before running in production environment so place a “-WhatIf” mark after the command, like this:

Get-ADUser -Filter * -SearchBase $ou | ForEach-Object { $newUpn = $_.UserPrincipalName.Replace($old,$new) $_ | Set-ADUser -server $server -UserPrincipalName $newUpn -WhatIf }