Created
September 1, 2015 22:15
-
-
Save chrisbrownie/dac2167b1161317222de to your computer and use it in GitHub Desktop.
Updates the UPN of all users in a specified location to match their primary SMTP address
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
$SearchBase = "DC=MargiesTravel,DC=com" | |
# Get all the users who have proxyAddresses under the margiestravel.com domain | |
foreach ($user in (Get-ADUser -SearchBase $SearchBase -LdapFilter '(proxyAddresses=*)')) { | |
# Grab the primary SMTP address | |
$address = Get-ADUser $user -Properties proxyAddresses | Select -Expand proxyAddresses | Where {$_ -clike "SMTP:*"} | |
# Remove the protocol specification from the start of the address | |
$newUPN = $address.SubString(5) | |
# Update the user with their new UPN | |
Set-ADUser $user -UserPrincipalName $newUPN | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment