Update/Change User Principal Name

Current UPN for users are set to domain.local. I added UPN Suffixes in AD. Now I can see the UPN in the drop down.

Is there a way to batch update all users to set their UPN based on their Primary SMTP address?

May 14th, 2015 3:54pm

Hi,

Just try this below one...

Import-Module ActiveDirectory

Get-ADUser -Filter {UserPrincipalName -like "*@olddomainname.local"} -SearchBase "DC=DomainName,DC=Local" |
ForEach-Object {
$UPN = $_.UserPrincipalName.Replace("olddomainname.local","newdomainname.org")
Set-ADUser $_ -UserPrincipalName $UPN
}

Free Windows Admin Tool Kit Click here and download it now
May 14th, 2015 4:04pm

Hi ,

We need to write the query in active directory based upon the domain suffix .You can refer the below mentioned picture and steps for this case.

Detailed Steps : dsa.msc --->Saved queries --->New --->Define query ---->Then click the drop down on the window --->select the custom search option ---->field --->user----->email address--->select the drop down and select ends with-->Enter the suffix of your primary domain ---click add ----->then click ok --->Then give name for that query and click ok option .Finally we should have to refresh the query to fetch up the objects based upon that query.

Once you got the related users object for that query then we need to select all the users object and go to the properties .On the second tab you have the option to set the new UPN suffix .

May 14th, 2015 4:19pm

Sorry maybe my question was not clear. I'd like to change users' UPN to match their primary email addresses.

I found article: http://doubledit.co.uk/2014/12/02/modify-upn-to-match-primary-smtp-address/

but command does not seem to work.

Free Windows Admin Tool Kit Click here and download it now
May 14th, 2015 4:53pm

Tried it again and it is actually working.

Tested it by piping it to a single user 1st to test.

Get-User -Identity "alias" | Where {-Not [string]::IsNullOrEmpty($_.WindowsEmailAddress) } | ForEach {Set-User Identity $_.Guid.ToString() UserPrincipalName $_.WindowsEmailAddress.ToString()}

Below command comes up with error: Pipeline not executed because a pipeline is already executing.

But for the most part, most of the users were actually updated around 70 percent were updated.

Get-User | Where {-Not [string]::IsNullOrEmpty($_.WindowsEmailAddress) } | ForEach {Set-User Identity $_.Guid.ToString() UserPrincipalName $_.WindowsEmailAddress.ToString()}

To get list of users that were not updated to be changed manually:

Get-User | Where {($_.UserPrincipalName -Like "*@domain.local")}

  • Edited by Andy Diaz 9 hours 31 minutes ago
  • Marked as answer by Andy Diaz 9 hours 0 minutes ago
May 14th, 2015 5:29pm

Tried it again and it is actually working.

Tested it by piping it to a single user 1st to test.

Get-User -Identity "alias" | Where {-Not [string]::IsNullOrEmpty($_.WindowsEmailAddress) } | ForEach {Set-User Identity $_.Guid.ToString() UserPrincipalName $_.WindowsEmailAddress.ToString()}

Below command comes up with error: Pipeline not executed because a pipeline is already executing.

But for the most part, most of the users were actually updated around 70 percent were updated.

Get-User | Where {-Not [string]::IsNullOrEmpty($_.WindowsEmailAddress) } | ForEach {Set-User Identity $_.Guid.ToString() UserPrincipalName $_.WindowsEmailAddress.ToString()}

To get list of users that were not updated to be changed manually:

Get-User | Where {($_.UserPrincipalName -Like "*@domain.local")}

  • Edited by Andy Diaz Thursday, May 14, 2015 9:57 PM
  • Marked as answer by Andy Diaz Thursday, May 14, 2015 10:27 PM
Free Windows Admin Tool Kit Click here and download it now
May 14th, 2015 9:28pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics