
Anyway, the second bit (2) is the account disabled bit.
Microsoft has given us a way to make a search filter that can search against a bit in an attribute, called LDAP matching rules. They are specified by OID's (long ugly numbers). According to the Search Filter Syntax page (http://msdn.microsoft.com/en-us/library/aa746475(VS.85).aspx), 1.2.840.113556.1.4.803 is equivelant to a bitwise AND.
So here's the script. The search filter does a bitwise AND of the contents of the useraccountcontrol attribute and the number 2 (remember the 2 bit means disabled). So the script searches for everyone in your AD that has the 2 bit set (disabled users).
use Win32::OLE;
$dse=Win32::OLE->GetObject("LDAP://RootDSE"); $root=$dse->Get("RootDomainNamingContext"); $adpath="GC://$root"; $base="<".$adpath.">";
$connection = Win32::OLE->new("ADODB.Connection"); $connection->{Provider} = "ADsDSOObject"; $connection->Open("ADSI Provider"); $command=Win32::OLE->new("ADODB.Command"); $command->{ActiveConnection}=$connection; $command->{Properties}->{'Page Size'}=1000; $rs = Win32::OLE->new("ADODB.RecordSet");
$command->{CommandText}="$base;(&(objectCategory=User)(userAccountControl:1.2.840.113556.1.4.803:=2));displayName;subtree";
$rs=$command->Execute; until ($rs->EOF){ $displayName=$rs->Fields(0)->{Value}; print "$displayName\n"; $rs->MoveNext; }
No comments:
Post a Comment