Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Get Domain Members

by BravoTwoZero (Scribe)
on Sep 01, 2004 at 14:19 UTC ( #387531=sourcecode: print w/replies, xml ) Need Help??
Category: NT Admin
Author/Contact Info BravoTwoZero

This one was more of a lark. It's only possible because the Win32::NetAdmin module does so much of the heavy lifting (and it comes with Activestate Perl or SFU's Perl). I wrote it as a quick and easy report to my boss for how many non-NT-based systems we have joined to our domain (we still have a number of 95/98 desktops in use).

The program picks up the domain controller for the system from which it is run. We don't have a multi-domain environment, so you might need to run it more than once (and append the domain name to the clients) if you do admin multiple domains. It could be the basis for more data gathering from the clients (drives, ram, specific windows versions, running services). We don't need that here, but it's nice to have it around as a building block.

The script builds an array of each of the following: primary domain controller, backup domain controller, NT servers (NT,2000,2003), unix servers, mssql servers, NT workstations (NT,2000,XP) and non-NT workstations (WFW,95,98,ME). Again, we didn't require specific versions. We just wanted a quick view of who is a *real* domain member, since they will be authenticating solely with the DC running the PDC FSMO service.

Because the array of NT domain members includes Unix and NT servers, those get added to a hash so that they won't be reported as NT-class workstations. Then it all barfs out to stdout.

By the way, if you're reading this for NT Admin stuff, the chances are good that you'll find a lotta useful information here: Wayne's NT Resources for Administrators and Users.

# As long as you have the module, you should not have to change a thin

use Win32::NetAdmin;

my $PDC;
my $domain = Win32::DomainName or die "Unable to obtain the domain nam

Win32::NetAdmin::GetServers($PDC, $domain, SV_TYPE_DOMAIN_CTRL, \@pdc)
Win32::NetAdmin::GetServers($PDC, $domain, SV_TYPE_DOMAIN_BAKCTRL, \@b
Win32::NetAdmin::GetServers($PDC, $domain, SV_TYPE_SERVER_NT, \@nt);
Win32::NetAdmin::GetServers($PDC, $domain, SV_TYPE_SERVER_UNIX, \@nix)
Win32::NetAdmin::GetServers($PDC, $domain, SV_TYPE_SQLSERVER, \@mssql)
Win32::NetAdmin::GetServers($PDC, $domain, SV_TYPE_WORKSTATION, \@ntwk
Win32::NetAdmin::GetServers($PDC, $domain, SV_TYPE_WFW, \@wfw);

my @dc = (@pdc, @bdc);
my %nixem;
my %nowks;

foreach $dc (@dc) { $nowks{$dc} = "nowks"; }
foreach $wfw (@wfw) { $nowks{$wfw} = "nowks"; }
foreach $nix (@nix) { $nixem{$nix} = "unix"; $nowks{$nix} = "nowks"; }
foreach $nt (@nt) { $nowks{$nt} = "nowks"; }

print "\nNT/2000/2003 servers in the $domain domain:\n";
foreach $dc (@dc) { 
    if ($pdc[0] eq $dc) { print "$dc (pdc)\n"; } else { print "$dc (bd
+c)\n"; }
foreach $nt (@nt) { unless ($nixem{$nt} eq unix) { print "$nt\n"; } }

print "\nMSSQL servers in the $domain domain:\n";
foreach $mssql (@mssql) { print "$mssql\n"; }

print "\nUnix servers in the $domain domain:\n";
foreach $nix (@nix) { print "$nix\n"; }

print "\nWindows NT/2000/XP workstations in the $domain domain:\n";
foreach $ntwks (@ntwks) { unless ($nowks{$ntwks} eq nowks) { print "$n
+twks\n"; } }

print "\nWindows 95/98 workstations in the $domain domain:\n";
foreach $wfw (@wfw) { print "$wfw\n"; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://387531]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2021-01-19 06:18 GMT
Find Nodes?
    Voting Booth?