Wednesday, August 2, 2017

Dump or Search for SPN records

Here you go:

#########################
$SearchCriteria = "CX"  # ----- What you search for
#########################
$search = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$search.filter = "(servicePrincipalName=*)"
$results = $search.Findall()
Foreach($result in $results)
{
$userEntry = $result.GetDirectoryEntry()
If($($userEntry.name) -like "*$SearchCriteria*")
{
Write-host "Object Name = " $userEntry.name -backgroundcolor "yellow" -foregroundcolor "black"
Write-host "DN      =      "  $userEntry.distinguishedName
Write-host "Object Cat. = "  $userEntry.objectCategory
Write-host "servicePrincipalNames"
$i=1
foreach($SPN in $userEntry.servicePrincipalName)
{
Write-host "SPN(" $i ")   =      " $SPN       $i+=1
}
Write-host ""
}
}

No comments:

Post a Comment