Show Active Directory colored computerlist
This is a way to display all computer objects in Active Directory of the type “Server”. If the server is reachable, then display the name in green, otherwise red.
Get-ADComputer -filter 'OperatingSystem -like "*Server*"' -SearchBase 'dc=laakie,dc=local' | ForEach-Object {
$rtn = Test-Connection -CN $_.dnshostname -Count 1 -BufferSize 16 -Quiet
if ($rtn -match 'True') {
write-host -ForegroundColor green $_.dnshostname
} else {
Write-host -ForegroundColor red $_.dnshostname
}
}