Link to home
Start Free TrialLog in
Avatar of ajdratch
ajdratch

asked on

Powershell command to fix UPN

I need to change the UPN for all users so I can migrate to office 365. I accidentally ran a powershell command on the entire domain instead of the test OU. Now all users UPN is just the @ symbol. When I go to Properties / Accounts, user logon name is correct but instead of the .local or .com domain, I just have the @ Symbol.

I can not figure out how to replace @ with their internet domain.
ASKER CERTIFIED SOLUTION
Avatar of Vasil Michev (MVP)
Vasil Michev (MVP)
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ajdratch
ajdratch

ASKER

Thanks so much. The first command fix it
Pretty Straightforward:

$oldSuffix = ""
$newSuffix = "yourdomain.com"
$server = "Yourdomaincontroller"
Get-ADUser -ResultSize Unlimited | ForEach-Object {
$newUpn = $_.UserPrincipalName.Replace($oldSuffix,$newSuffix)
$_ | Set-ADUser -server $server -UserPrincipalName $newUpn
}


ref link:  https://blogs.technet.microsoft.com/canitpro/2015/07/07/step-by-step-changing-the-upn-suffix-for-an-entire-domain-via-powershell/