How to find a servicePrincipleName (SPN) in Active Directory using Perl. Click here to find an SPN using VBScript.
This script searches Active Directory for user accounts that have the specified SPN associated with them. This is handy if you have duplicate SPN's you want to get rid of. This is just another variation on my ADO search script in a previous post Search Active Directory from Perl Using ADO.
use Win32::OLE;
$spn="HTTP/myWebSite.mydomain.com";
$dse=Win32::OLE->GetObject("LDAP://RootDSE"); $root=$dse->Get("RootDomainNamingContext"); $adpath="GC://$root"; $base="<".$adpath.">"; $c = Win32::OLE->new("ADODB.Connection"); $c->{Provider} = "ADsDSOObject"; $c->Open("ADSI Provider"); $comm=Win32::OLE->new("ADODB.Command"); $comm->{ActiveConnection}=$c; $comm->{Properties}->{'Page Size'}=1000; $rs = Win32::OLE->new("ADODB.RecordSet");
$comm->{CommandText}="$base;(servicePrincipalName=$spn);cn,samAccountName;subtree"; $rs=$comm->Execute; until ($rs->EOF){ $cn=$rs->Fields(0)->{Value}; $sam=$rs->Fields(1)->{Value}; print "$spn is registered to $sam\n"; $rs->MoveNext; }
0 comments:
Post a Comment