I’m setting up our forest to access office 365. Part of the setup process is to make sure you have UPN set for all users. Our active directory forest has multiple domains each with their own DNS name space. I chose to use one UPN suffix for the entire forest.
I tried to get the script to run for all users in the forest but in the end I had to update the script with the domains and run it once for each.
Replace domain1.com with your AD domain name.
$users = Get-ADUser -filter * -Server domain1.com -resultsetsize $null
foreach($user in $users)
$UPN = "$($user.sAMAccountName)@domain1.com"
# Write-Host "Setting " $UPN
$user | Set-ADUser -UserPrincipalName $UPN
Hope this helps someone. 🙂