Contact Info

Crumbtrail

ActiveXperts.com » Administration » Scripts » WMI » perl sample

MSAD perl sample code

The foundations for Manageability in Windows is Windows Management Instrumentation (WMI; formerly WBEM) and WMI extensions for Windows Driver Model (WDM).

ActiveXperts Network Monitor provides the ability to build monitor check routines based on WMI. ActiveXperts has collected more than a hundred WMI samples. You can use these samples as a base for new check routines you can write yourself. The MSAD WMI class can be used in ActiveXperts Network Monitor to monitor your servers.


Sample Code

use Win32::OLE('in');

my $computer = ".";

my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\MicrosoftActiveDirectory") or die "WMI connection failed.\n";
my $colItems = $objWMIService->ExecQuery("SELECT * FROM MSAD_DomainController", "WQL");

foreach my $objItem (in $colItems) {
	print "CommonName: $objItem->{CommonName}\n";
	print "DistinguishedName: $objItem->{DistinguishedName}\n";
	print "IsAdvertisingToLocator: $objItem->{IsAdvertisingToLocator}\n";
	print "IsGC: $objItem->{IsGC}\n";
	print "IsNextRIDPoolAvailable: $objItem->{IsNextRIDPoolAvailable}\n";
	print "IsRegisteredInDNS: $objItem->{IsRegisteredInDNS}\n";
	print "IsSysVolReady: $objItem->{IsSysVolReady}\n";
	print "NTDsaGUID: $objItem->{NTDsaGUID}\n";
	print "PercentOfRIDsLeft: $objItem->{PercentOfRIDsLeft}\n";
	print "SiteName: $objItem->{SiteName}\n";
	print "TimeOfOldestReplAdd: $objItem->{TimeOfOldestReplAdd}\n";
	print "TimeOfOldestReplDel: $objItem->{TimeOfOldestReplDel}\n";
	print "TimeOfOldestReplMod: $objItem->{TimeOfOldestReplMod}\n";
	print "TimeOfOldestReplSync: $objItem->{TimeOfOldestReplSync}\n";
	print "TimeOfOldestReplUpdRefs: $objItem->{TimeOfOldestReplUpdRefs}\n";
	print "\n";
	print "########\n";
	print "\n";
}