Get All DCs in the Entire Forest
Getting a know a new environment for a new client and I a quickly needed information about all domain controllers in the entire forest.
Wrote a small little script to provide me all the information I needed:
Import-Module ActiveDirectory
function Get-AllDCsInForest{
[CmdletBinding()]
param(
[string]$ReferenceDomain = $env:USERDOMAIN
)
$ForestObj = Get-ADForest -Server $ReferenceDomain
foreach($Domain in $ForestObj.Domains) {
Get-ADDomainController -Filter * -Server $Domain | select Domain,HostName,Site, IPv4Address, OperatingSystem, OperatingSystemVersion
}
}
Get-AllDCsInForest| Export-Csv -Path C:\Scripts\AllDcs.txt -NoTypeInformation