Skip to content

Instantly share code, notes, and snippets.

@realeroberto
Created August 11, 2014 13:34
Show Gist options
  • Save realeroberto/c5db18c5d912e3802461 to your computer and use it in GitHub Desktop.
Save realeroberto/c5db18c5d912e3802461 to your computer and use it in GitHub Desktop.
Ping a list of hosts, in PowerShell.
#
# ping-host-list
#
# ping a list of hosts
#
$Host_List_Path = ".\hostlist.txt"
# ping a single host
Function Ping-Host {
param($InputObject = $null)
BEGIN {$status = $False}
PROCESS {
$processObject = $(if ($InputObject) {$InputObject} else {$_})
if( (Test-Connection $processObject -Quiet -count 1)) {
$status = $True
} else {
$status = $False
}
}
END {return $status}
}
# ping a list of hosts
Function Ping-HostList {
param($InputObject = $null)
PROCESS {
Get-Content $InputObject | %{ if (Ping-Host $_) {
Write-Host -ForegroundColor green $_ ;
} else {
Write-Host -ForegroundColor red $_ ;
}
}
}
}
Ping-HostList $Host_List_Path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment