Ping domain controllers

Are your domain controllers up and running?  Sure?

One test to determine if domain controllers is to ping the system. Doing that manually for a bunch of domain controllers is a pain – its very easy to miss one & it involves lots of typing. This post showed how to find the domain controllers in your domain. we can put that together with a little function and we have a way to automate this.

function test-computer {            
param (            
 $result = New-Object -TypeName PSObject -Property @{            
  DomainController = $computername            
  Status = "Unavailable"            
 if (Test-Connection -ComputerName $computername -Count 1 -Quiet){            
  $result.Status = "Available"            
 Write-Output $result            
$ou = "OU=Domain Controllers,DC=Manticore,DC=org"            
Get-ADDomainController -Filter * |             
select @{N="computername"; E={$($_.Name)}} |            
"`nAD provider"            
Get-ChildItem -Path Ad:\$ou |             
select @{N="computername"; E={$($_.Name)}} |            
Get-QADComputer -ComputerRole "DomainController" |             
select @{N="computername"; E={$($_.Name)}} |            
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()            
$domain.FindAllDomainControllers() |             
select -ExpandProperty Name |            

A function that uses Test-Connection determines if the domain controller is reachable. it has computername as a parameter and is set to accept input from the pipeline. The return object is created before the ping and the status is changed if its successful – cuts down on code!

Our four methods each generate a list of domain controllers but they use name instead of computername. We can use select to create a property with the right name or we can just pass the name and we pick it by type. In that case we have to use –expandproperty to make sure we get the value.

This entry was posted in PowerShell and Active Directory. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s