List Servers in Active Directory

A Script to List Servers in Your Active Directory:  There are two ways to maintain a list of servers in your data center. Grab a clipboard and walk the aisles of your data center, or get the list using Active Directory scripts!  Here's a Perl script that searches your domain for any computers that have the word "server" in the operating system.  Just another ADO search;  we're searching for computer objects (objectCategory=computer) whose operatingSystem attribute has the string "server" in it (operatingSystem=*server*). Like I've said before, learning how to build the query is the key to getting information out of AD. It's a piece of cake. 

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";
$connection = Win32::OLE->new("ADODB.Connection");
$connection->{Provider} = "ADsDSOObject";
$connection->Open("ADSI Provider");
$command->{Properties}->{'Page Size'}=1000;
$rs = Win32::OLE->new("ADODB.RecordSet");
until ($rs->EOF){
 print "$cn\t$os\n";
 print OUT "$cn\t$os\t$dn\n";
close OUT;


Post a Comment

Related Posts Plugin for WordPress, Blogger...