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

Consideration to Convert Cisco VoIP to Asterisk

Benefits: - Cisco requires 20% maintenance fee yearly from Cisco partner - Cisco upgrade path…

PowerShell: Command to Retrieve Windows Applications List

The following the the PoSH equivalent of appwiz.cpl in Windows: PS> invoke-command TestWindows {Get-Package -Provider…

PowerShell: Audit Domain Controller Certificates

function auditDcCerts{ try{ write-host "Gathering Domain Controller Names..." Import-Module ActiveDirectory $osInfo = Get-CimInstance -ClassName Win32_OperatingSystem…