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

Conversion Plan (draft 0.1)

Overview There shall be three phases of this project to ensure minimal disruption to production…

How To Install Graylog in a Kubernetes Cluster Using Helm Charts

The following narrative is based on the assumption that a Kubernetes (current stable version 20.10)…

How To Use Command Line to Configure iDrac Settings

Step 1: Install RacADM $computerlist=@' SERVER1 SERVER2 '@ $computernames=@($computerlist -split "`n")|%{$_.Trim()} $fileURL="https://dl.dell.com/FOLDER08543783M/1/DellEMC-iDRACTools-Web-WINX64-10.3.0.0-4945.exe" $expectedExecutable='racadm.exe' $expectedInstallPath='C:\Program Files\Dell\SysMgt\iDRACTools\racadm'…