Find existing UPN in Forest

A userPrincipalName (UPN) must be unique in a Active Directory Forest. To check for an existing UPN use the following lines. The script expects that all DC’s within the Root Domain are GC enabled .

1
2
3
4
5
6
7
8
9
10
11
12
$RootDomain = "Contoso.com"
$DomainControllerRoot = (Get-ADDomainController -Filter * -server $RootDomain | select Hostname).hostname[0]
$GlobalCatalog = $DomainControllerRoot +":3268"
$UserPrincipalName = "Name@namespace.com"
if ((get-aduser -ldapfilter "(userPrincipalName=$UserPrincipalName)" -server $GlobalCatalog ).userPrincipalName.length -gt 0)
{
Write-host "UPN NOT unique in Forest : $UserPrincipalName "
}
Else
{
Write-host "UPN UNIQUE in Forest : $UserPrincipalName " 
}
Print Friendly, PDF & Email
This entry was posted in Information Technology and tagged , , . Bookmark the permalink.

Comments are closed.