List all SPNs in your Domain using Powershell
By peter.stilgoe
The below script lists all SPNs in your domain using Powershell (The service type is specified on the 1st line, in this case it is returning all HTTP SPNs):
$serviceType="HTTP"
$spns = @{}
$filter = "(servicePrincipalName=$serviceType/*)"
$domain = New-Object System.DirectoryServices.DirectoryEntry
$searcher = New-Object System.DirectoryServices.DirectorySearcher
$searcher.SearchRoot = $domain
$searcher.PageSize = 1000
$searcher.Filter = $filter
$results = $searcher.FindAll()
foreach ($result in $results){
$account = $result.GetDirectoryEntry()
foreach ($spn in $account.servicePrincipalName.Value){
if($spn.contains("$serviceType/")){
$spns[$("$spn`t$($account.samAccountName)")]=1;
}
}
}
$spns.keys
This & other useful powershell scripts can be found here Useful Powershell Scripts
Kerberos , Powershell , SPNs 


February 13th, 2012
