Posted On May 30, 2019

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

kimconnect 0 comments
blog.KimConnect.com >> Windows >> 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 *

Related Post

How to Create a New Jenkins Job to Call a PowerShell Script with Credentials

1. PowerShell & Secured Credentials Support Check for PowerShell support: Manage Jenkins > Plugin Manager…

Enable File Server to Have Multiple Alias Host Names

Regedit: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0, create Multi-String Value = BackConnectionHostNames with values of the CNAMES of the file…