Scripts to explore your Active Directory Configuration: Your Active Directory forest is divided into sections, called directory partitions, also referred to as naming contexts. There is a partition for each domain in your forest, and some other special partitions that include a DNS storage partition for each domain, a forest-wide DNS storage partition, a partition for the Schema, and a partition for the forest configuration.
The Configuration partition contains various forest-wide configuration information. The list of domains in the forest, the list of sites and subnets, domain controller replication partners, and forest-wide services are all defined in the Configuration partition.
Some of the information in the Configuration container is visible in the AD Sites and Services tool. However, much of it is visible only in generic tools like adsiedit, Ldp, or Active Directory scripts. Have a look around in the Confguration partition, it's very informative.
You can connect to the Configuration partition using a script, by connecting to the container cn=configuration,dc=myForest,dc=net. Of course, we don't like to hard-code anything in our scripts, so we'll use rootDSE to discover the path of the Configuration container like so:
use Win32::OLE; $dse=Win32::OLE->GetObject("LDAP://RootDSE"); $config=$dse->Get("ConfigurationNamingContext"); print "Path to Configuration container is: $config\n";
use Win32::OLE;
$dse=Win32::OLE->GetObject("LDAP://RootDSE"); $config=$dse->Get("ConfigurationNamingContext");
$partitionsContainer=Win32::OLE->GetObject("LDAP://cn=Partitions,$config");
foreach $partition (in $partitionsContainer){ print $partition->Get("ncName")."\n"; }
use Win32::OLE;
$dse=Win32::OLE->GetObject("LDAP://RootDSE"); $config=$dse->Get("ConfigurationNamingContext");
$partitionsContainer=Win32::OLE->GetObject("LDAP://cn=Partitions,$config");
foreach $partition (in $partitionsContainer){ if($partition->{netbiosname}){ print $partition->Get("ncName")."\n"; } }
use Win32::OLE;
$dse=Win32::OLE->GetObject("LDAP://RootDSE"); $config=$dse->Get("ConfigurationNamingContext");
$partitionsContainer=Win32::OLE->GetObject("LDAP://cn=Partitions,$config");
foreach $partition (in $partitionsContainer){ if($partition->{netbiosname}){ print "Domain Controllers in the $partition->{netbiosName} domain:\n"; $domainControllersContainer=Win32::OLE->GetObject("LDAP://ou=domain controllers,".$partition->Get("ncName")); foreach $dc (in $domainControllersContainer){ print "\t$dc->{cn}\n"; } } }
To get a list of sites from the AD, you can simply connect to the sites container and list the site objects, as in the script below:
use Win32::OLE;
$dse=Win32::OLE->GetObject("LDAP://RootDSE"); $config=$dse->Get("ConfigurationNamingContext");
$sitesContainer=Win32::OLE->GetObject("LDAP://cn=sites,$config");
foreach $site (in $sitesContainer){ if($site->{class} eq "site"){ print "$site->{cn}\t$site->{description}\n"; } }
use Win32::OLE;
$dse=Win32::OLE->GetObject("LDAP://RootDSE"); $config=$dse->Get("ConfigurationNamingContext");
$subnetsContainer=Win32::OLE->GetObject("LDAP://cn=subnets,cn=sites,$config");
foreach $subnet (in $subnetsContainer){ print "$subnet->{cn}\t"; if($site=Win32::OLE->GetObject("LDAP://$subnet->{siteObject}")){ print "$site->{cn}\n"; }else{ print "\n"; } }
0 comments:
Post a Comment