anonit

Update UPN for AD accounts in a specific OU recursive

Oct 7th, 2018
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Update UPN for AD accounts in a specific OU recursive
  2.  
  3. Import-Module ActiveDirectory
  4. $oldSuffix = "anonit.local"
  5. $newSuffix = "anonit.net"
  6. $ou = "OU=UsersOU,DC=anonit,DC=local"
  7. $server = "anonit-dc-01"
  8. Get-ADUser -SearchBase $ou -filter * | ForEach-Object {
  9.     $newUpn = $_.UserPrincipalName.Replace($oldSuffix,$newSuffix)
  10.     $_ | Set-ADUser -server $server -UserPrincipalName $newUpn
  11. }
Add Comment
Please, Sign In to add comment