Share This Post

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 continued…

Share This Post

Ying Li obtained a Master degree of Medicine in China and worked in the medical field before he came to the states in 1996. He made the career switch from troubleshooting people to troubleshooting computers after he came to the states. Not entirely a surprise there, if you know that his second preference for college is Mathematics. Ying is two times Admin Framework MVP awardee (2007-2008).His previous employment experience in the US includes UUNET, MCI WorldCom. MMC (Marsh & McLennan Companies), Merrill Lynch. He is currently employed by Related Companies as a Senior Infrastructure Engineer. He is proficient in virtually all Microsoft products (Office/Back office). His craving for efficiency naturally leads him to scripting, automation and before you know it, PowerShell! He is currently a MCSE (NT4, 2000, 2003) and MCITP Server Administrator. Ying enjoys wines and love to travel. His non work related passion is to advocate Health Living!

Leave a Reply