For various reasons I’ve found myself needing to fix customer sites where the User Principal Name (UPN) was not present for AD user accounts.
Most frequently this is because the environment was once NT4, which did not require this attribute. Whatever the reason, I’ve fixed it using PowerShell.
If you don’t have 2008 R2 domain controllers you can use the free Quest PowerShell add-ins downloaded here.
If you DO have 2008 R2 domain controllers you can use the native Active Directory Module for Windows PowerShell.
Below is a script you can use for either scenario. This will take all users with missing UPNs from the “My Users” OU in the “contoso.local” domain and set their UPN to username@contoso.local
Quest:
Get-QADUser –SearchRoot “contoso.local/My Users” -UserPrincipalName $null -SizeLimit 0 | % {$CompleteUPN = $_.samaccountname +"@contoso.local"; Set-QADUser -Id $_.DN -UserPrincipalName $CompleteUPN}
2008 R2 Native:
Get-ADUser -Filter {-not (UserPrincipalName -like '*')} -SearchBase 'OU=My Users,DC=contoso,DC=local' | % {$CompleteUPN = $_.SamAccountName + "@contoso.local" ; Set-ADUser -Identity $_.DistinguishedName -UserPrincipalName $CompleteUPN}
I too have come across a few environments where the UPN doesn’t exist for most users… I wondered why it was but your explanation of this happening when the domain has been upgraded from NT4 clears that up 🙂 so thanks for answering one of those little questions that I never quite got round to looking into 🙂
PS nice little script, I’m more of a .NET person myself but Powershell certainly seems to be getting more and more useful
When running this script, does it populate both the user logon name and the following field with the UPN?
There is actually no attribute called “user logon name”. That is just how the UPN is displayed in Active Directory Users and Computers.
Thanks for this. Issue I had was after migrating to Exchange 2013 I couldn’t adjust quotas on a user in the EAC unless the UPN was there. Our AD started with NT4.
you have just saved me HOURS!!!! thank you so much!!!