Created
March 27, 2018 06:23
-
-
Save nordineb/18c08ef430a42a9cf65a888c7985bff2 to your computer and use it in GitHub Desktop.
List all SPNs used in your Active Directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cls | |
$search = New-Object DirectoryServices.DirectorySearcher([ADSI]"") | |
$search.filter = "(servicePrincipalName=*)" | |
## You can use this to filter for OU's: | |
## $results = $search.Findall() | ?{ $_.path -like '*OU=whatever,DC=whatever,DC=whatever*' } | |
$results = $search.Findall() | |
foreach( $result in $results ) { | |
$userEntry = $result.GetDirectoryEntry() | |
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 "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment