Skip to content

Instantly share code, notes, and snippets.

@sweeneyrobb
Created January 8, 2018 19:25
Show Gist options
  • Save sweeneyrobb/eae4e5aa20313a246c86cac11f6205fd to your computer and use it in GitHub Desktop.
Save sweeneyrobb/eae4e5aa20313a246c86cac11f6205fd to your computer and use it in GitHub Desktop.
A PowerShell script that will mass assign UPNs for users in previous domain.
$oldSuffix = "old-domain.com"
$newSuffix = "new-domain.com"
Get-MsolUser |
Where-Object { $_.UserPrincipalName.EndsWith($oldSuffix) } |
ForEach-Object {
Set-MsolUserPrincipalName -ObjectId $_.ObjectID -NewUserPrincipalName ($_.UserPrincipalName.Replace($oldSuffix, $newSuffix))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment