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




Share

, ,

categoriaKerberos, Powershell commentoNo Comments dataFebruary 13th, 2012

About... peter.stilgoe

peter.stilgoeThis author published 497 posts in this site.
Sharepoint, InfoPath, K2, Nintex, Business Process Mapping, Business Intelligence, Automation, ECM, Document Management, Document Imaging, Internet Marketing & Online Business Consultant Email / MSN: pstilgoe@hotmail.com LinkedIn: Pete Stilgoe - Sharepoint Consultant









Share

FacebookTwitterEmailWindows LiveTechnoratiDeliciousDiggStumbleponMyspaceLikedin

No Comments

(Required)
(Required, will not be published)