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?
Technology Tips and News
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?
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
}
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 .
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.
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")}
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")}