Skip to content

Instantly share code, notes, and snippets.

@davegreen
Created May 29, 2014 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davegreen/ca0e8af2378f4e5f87d7 to your computer and use it in GitHub Desktop.
Save davegreen/ca0e8af2378f4e5f87d7 to your computer and use it in GitHub Desktop.
Quick one-liner for setting UPNs for users to match their email address (useful for working with Azure, O365, etc.)
#Set UPN for all users with mobile phone numbers to email address
Get-ADuser -Filter * -Properties mobilephone, mail | where {$_.mobilephone -and $_.mail -ne $_.userPrincipalName} | ForEach-Object {Set-ADuser -Identity $_.ObjectGUID -UserPrincipalName $_.mail}
#Set UPN for all users to email address
Get-ADuser -Filter * -Properties mail | where {$_.mail -ne $_.userPrincipalName} | ForEach-Object {Set-ADuser -Identity $_.ObjectGUID -UserPrincipalName $_.mail}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment