Ping AD Computer SearchBase

image_pdfimage_print

Powershell Ping multiple AD Computer

Welcher Computer ist Online und hat welche IP?

Ping multiple AD Computer SearchBase

$csv = “C:\Temp\Ping.csv”
$Computers = Get-ADComputer -Filter * -SearchBase “OU=Server,OU=Machines,OU=ORG,DC=ndsedv,DC=de” | Select Name | Sort-Object Name
$Computers = $Computers.Name
$Headers = “ComputerName,IP Address”
$Headers | Out-File -FilePath $csv -Encoding UTF8
foreach ($computer in $Computers)
{
Write-host “Pinge $Computer”
$Test = Test-Connection -ComputerName $computer -Count 1 -ErrorAction SilentlyContinue -ErrorVariable Err
if ($test -ne $null)
{
$IP = $Test.IPV4Address.IPAddressToString
$Output = “$Computer,$IP”
$Output | Out-File -FilePath $csv -Encoding UTF8 -Append
}
Else
{
$Output = “$Computer,$Err”
$output | Out-File -FilePath $csv -Encoding UTF8 -Append
}
cls
}