Getting all domain controllers and their site names in the forest
The function discussed in this section is a simple wrapper on top of the Get-ADDomainController
cmdlet to query all the domain controllers in forest and display frequently referred-to details, such as DC name, domain name, site name—whether these names are global catalog servers or not—and reachability of the domain controller:
Function Get-DCDetails { [CmdletBinding()] Param( ) $Domains = (Get-ADForest).Domains $DCs = $Domains | % { Get-ADDomainController -Filter * -Server $_ } foreach($DC in $DCs) { $OutputObj = New-Object -TypeName PSObject -Property @{ DCName = $User.Name; DCDomain = $null; IsGC = $null; SiteName = $Null; IsOnline = $null } if(Test-Connection -Computer $DC -Count 1 -quiet) { $OutputObj.IsOnline = $true } else { $OutputObj.IsOnline = $false } $OutputObj.DCName = $DC.HostName $OutputObj.DCDomain = $DC.Domain $OutputObj.IsGC...