PowerShell: Script to Obtain List of Sites and Associated Domain Controllers

Script:

if (!(get-module -name "ActiveDirectory") ){Add-WindowsFeature RSAT-AD-PowerShell; import-module -name "ActiveDirectory" -DisableNameChecking | out-null }
$sites=(Get-ADDomainController -filter * | select ServerObjectDN) | foreach-object -process {$_ | ConvertFrom-String -Delimiter "," | select P1,P3} | foreach-object {$a=$_.P1 -replace "@{ServerObjectDN=CN=";$b=$_.P3 -replace "CN=";$b+","+$a;} | Sort-Object | foreach-object -process {$_ | ConvertFrom-String -Delimiter ","} | Group-Object P1
foreach ($site in $sites){
$site.Name+": "+$site.Group.P2
}

Output:

Irvine: SHERVER1 SHERVER2
Irvine-PublicDMZ: SHERVER3 SHERVER4
Phoenix: DC5 DC6
Phoenix-PublicDMZ: DC6 DC7
Phoenix-WebDMZ: DC8 DC9
Florida: DC10 DC11

Leave a Reply

Your email address will not be published. Required fields are marked *