Wednesday, September 25, 2013

Powershell Script to Connect to Domain Controllers

We have been seeing some issues with our servers not being able to connect to DC's - to help diagnose the issues the following scripts were useful 

This gets all the DC's and pings

[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() | % { $_.DomainControllers } | %{Test-Connection $_.Name}

The next one-liner connects to each of the DC's on 389

[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() | % { $_.DomainControllers } | %{$o=new-object Net.Sockets.TcpClient;$o.Connect( $_.IPAddress, 389); new-object PSObject -Property @{name=$_.Name;connected=$o.Connected}}

No comments:

Post a Comment