Created
August 11, 2014 13:34
-
-
Save realeroberto/c5db18c5d912e3802461 to your computer and use it in GitHub Desktop.
Ping a list of hosts, in PowerShell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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