PowerShell to identify the GlobalCatalog Servers and more in your AD environment - Part I
I recently started a new job (about two months for now). As you would imagine, I would have a lot questions. Some of them related to AD. How the AD setup? What’s the domain /forest function level? How many sites? Where are the GlobalCatalog Servers or BridgeHeadServers? etc.
How can I get those informations?
Ask coworkers is one option, What if they are busy and they don’t know these information on top of their head?
Of course, we can go to Active Directory Sites and Services and go to each server – right click NTDS settings-properties to find the GCs. That would be a little awkward in 21st Century, don’t you think?
For GCs, I can do a NSLOOKUP gc._msdcs.mydomain, it give me a bunch of IP Addresses.
Well, don’t forget we are in PowerShell Times!
$myforest = [System.DirectoryServices.AcitveDirectory.Forest]::GetCurrentForest()
Initially I got “Unable to find type [System.DirectoryServices.AcitveDirectory.Forest]: make sure that the assembly containing this type
is loaded.”
No Problem, I know how to handle that – run the below script first
if (-not ([appdomain]::CurrentDomain.getassemblies() |? {$_.ManifestModule -like “System.DirectoryServices.ActiveDirectory.Forest”})) {[void][System.Reflection.Assembly]::LoadWithPartialName(’System.DirectoryServices.ActiveDirectory.Forest’)}
Run the above script again:
PS C:\Documents and Settings\yl.admin\My Documents\PS> $myforest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
PS C:\Documents and Settings\yl.admin\My Documents\PS> $myforest
Name : mydomain.com
Sites : {NYW, NCR, NYS, CAG...}
Domains : {mydomain.com}
GlobalCatalogs : {abc.mydomain.com; xyz.mydomain.com…} .}
ApplicationPartitions : {DC=ForestDnsZones,DC=related,DC=com, DC=DomainDnsZones,DC=related,DC=com}
ForestMode : Windows2000Forest
RootDomain : mydomain.com.com
Schema : CN=Schema,CN=Configuration,DC=related,DC=com
SchemaRoleOwner : xyz.mydomain.com
NamingRoleOwner : xyz.mydomain.com
How about
PS C:\Documents and Settings\yl.admin\My Documents\PS> $myforest.Sites
and
PS C:\Documents and Settings\yl.admin\My Documents\PS> $myforest | gm
Fun starts from here and sky is your limit! – to be continue…