Skip to content

Instantly share code, notes, and snippets.

@azure365pro
Created May 13, 2020 16:55
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 azure365pro/99fe2f090516fab9de88ad7c7da38598 to your computer and use it in GitHub Desktop.
Save azure365pro/99fe2f090516fab9de88ad7c7da38598 to your computer and use it in GitHub Desktop.
Change User Principal Name equals Email Address Automation
# NOTE : Before running the script run below commands to check which are the mailboxes it will apply to
# Get-Mailbox -ResultSize Unlimited | Where-Object {$_.Primarysmtpaddress -ne $_.UserPrincipalname}
# Get-Mailbox -ResultSize Unlimited | Where-Object {$_.Primarysmtpaddress -ne $_.UserPrincipalname} | ForEach-Object {Set-Mailbox $_.identity -UserPrincipalName $_.Primarysmtpaddress -whatif}
# Include Exchange Powershell Module
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
#Lists All Mailboxes
#Checks Email and UPN are same
#Lists which are not email
#Applies UPN Matching email
Get-Mailbox -ResultSize Unlimited | Where-Object {$_.Primarysmtpaddress -ne $_.UserPrincipalname} | ForEach-Object {Set-Mailbox $_.identity -UserPrincipalName $_.Primarysmtpaddress}
# Exit Exchange Powershell Module
Remove-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment