Monday, July 15, 2019

Quickly get the Domain Controllers via Powershell

I use this all the time, and get-adDomainControllers is a broken command, so this quickly grabs the DCs and can get other info if needed.



$AllDCS=[system.directoryservices.activedirectory.Forest]::GetCurrentForest().domains | %{$_.DomainControllers.name}

$AllDCS | foreach {
    Get-ADdomaincontroller $_.trim() | select Hostname, IPv4Address
    }
  


NETDC02.nsw.gov.au 20.48.31.116                
NETDC04.nsw.gov.au 20.48.31.117    
                                            

                                         

1 comment:

Troy Sosa said...

Great reading youur post

Blog Archive