Skip to content

Instantly share code, notes, and snippets.

@chrisbrownie
Created September 1, 2015 22:15
Show Gist options
  • Save chrisbrownie/dac2167b1161317222de to your computer and use it in GitHub Desktop.
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
$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