getting Domain Controller info

Next time someone asks you for the IP address or name of al the DCs in your environment try using [System.DirectoryServices.ActiveDirectory.Domain]  to enumerate it for you

This little script just enumerates the attribute values and displays them on screen.  You could easily build this into a full report and export it into any format you like/

cls
$padright = 90
$myCount = 0
$myDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
# list forest
$Forest = $myDomain.Forest
$Sites = $Forest.Sites
Write-Host “Forest Name….: $($Forest.RootDomain)”
Write-Host “Forest Mode….: $($Forest.ForestMode)”
Write-Host “No. of sites…: $($Sites.Count)”
$GCs = $Forest.GlobalCatalogs
$SchemaMaster = $Forest.SchemaRoleOwner
$DomainNameMaster = $Forest.NamingRoleOwner
Write-Host “”
Write-Host “Domain Details”
$Domains = $Forest.Domains
$forestRootDomain = $Forest.Name
$forestDomainInfo = @{}
ForEach ($Domain in $Domains) {
$domainFSMOs = “” | Select PDCe,RIDMaster,InfrastructureMaster
Write-Host “”.padright($padright,“=”)
Write-Host “Domain : $($Domain.Name)”
Write-Host “”.padright($padright,“=”)
ForEach ( $DomainController in $Domain.DomainControllers ) {
Write-Host “DC Name….: $($DomainController.Name)”Write-Host “OS Version.: $($DomainController.OSVersion)”
Write-Host “Site…….: $($DomainController.SiteName)”
Write-Host “IP Address.: $($DomainController.IPAddress)”
if ( $($DomainController.Roles).Count -gt 0 ) {
Write-Host “DC Roles:”
forEach ($role in $DomainController.Roles) {
switch ($role) {
“PdcRole” {
$domainFSMOs.PDCe = $DomainController.Name
break
}
“RidRole” {
$domainFSMOs.RIDMaster = $DomainController.Name
break
}
“InfrastructureRole” {
$domainFSMOs.InfrastructureMaster = $DomainController.Name
}
}
$rolestring = $role.toString().toUpper().Substring(0,$role.toString().toUpper().indexof(‘ROLE’))Write-Host “`t $RoleString”
}
}
Write-Host “”.padright($padright,“=”)
}
$forestDomainInfo.Add($($Domain.Name),$domainFSMOs)

}

Write-Host “”.padright($padright,“-“)
Write-Host “”.padright($padright,“=”)
Write-Host “Forest Name….: $($Forest.RootDomain)”
Write-Host “Forest Mode….: $($Forest.ForestMode)”
Write-Host “$($GCs.count) Global Catalogue Servers”
Write-Host “”.padright($padright,“=”)
Write-Host “$($Sites.Count) Sites:”
ForEach ( $Site in $Sites ) { Write-Host “`t $site” }
Write-Host “”.padright($padright,“=”)
Write-Host “”
Write-Host “Forest Root FSMO Holders”
Write-Host “”
Write-Host “Schema Master ……. : $SchemaMaster”
Write-Host “Domain Naming Master. : $DomainNameMaster”
Write-Host “Domain Naming Master. : $DomainNameMaster”
Write-Host “”.padright($padright,“=”)
Write-Host “Child Domain FSMO Holders”
Write-Host “”.padright($padright,“=”)
ForEach ( $childDomain in $forestDomainInfo.GetEnumerator() ) {
Write-Host “Domain: $($childDomain.name)”
Write-Host “PDCe…………. : $($childDomain.Value.PDCe)”
Write-Host “RID Master……. : $($childDomain.Value.RIDMaster)”
Write-Host “IM Master…….. : $($childDomain.Value.InfrastructureMaster)”
Write-Host “”.padright($padright,“-“)
}
Write-Host “”.padright($padright,“=”)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.