Created
February 20, 2020 15:20
-
-
Save iyre/e6c1c24cf20d174186acea78cc3a9f0c to your computer and use it in GitHub Desktop.
Batch replace domain name portion of UPN in active directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# batch replace domain name portion of UPN in active directory | |
$SearchBase = "OU=Domain Users, DC=contoso, DC=com" | |
$OldDN = "contoso.com.local" | |
$NewDN = "contoso.com" | |
Import-Module ActiveDirectory | |
Get-ADUser -Filter { UserPrincipalName -like "*$OldDN" } -SearchBase $SearchBase | | |
ForEach-Object { | |
Write-Host $_.Name | |
$Upn = $_.UserPrincipalName.Replace( $OldDN, $NewDN ) | |
Set-ADUser $_ -UserPrincipalName $Upn | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment