The script returns the server name, operating system version, and the distinguished name (the full path to the computer account in Active Directory), and prints it out to a text file (servers.txt).
I saw someone searching for this recently, so whoever you are, here it is!
use Win32::OLE;
open OUT,">servers.txt\n";
$dse=Win32::OLE->GetObject("LDAP://RootDSE"); $root=$dse->Get("DefaultNamingContext"); $adpath="LDAP://$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=Computer)(operatingSystem=*server*));cn,distinguishedName,operatingSystem;subtree";
$rs=$command->Execute;
until ($rs->EOF){ $cn=$rs->Fields(0)->{Value}; $dn=$rs->Fields(1)->{Value}; $os=$rs->fields(2)->{Value}; print "$cn\t$os\n"; print OUT "$cn\t$os\t$dn\n"; $rs->MoveNext; }
close OUT;
No comments:
Post a Comment