Skip to content

Instantly share code, notes, and snippets.

@dtrac
Created September 7, 2017 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtrac/23f584582877dc3f6208aaa9f031f768 to your computer and use it in GitHub Desktop.
Save dtrac/23f584582877dc3f6208aaa9f031f768 to your computer and use it in GitHub Desktop.
Test Server Connections and Create 2x Arrays
$Servers = @("localhost","badhost1","badhost2")
$contactable = @()
$uncontactable = @()
foreach ($server in $servers){
if (Test-Connection -Count 1 -Quiet -ComputerName $Server){
Write-Output "$Server is contactable"
$contactable += $Server
}
else {
Write-Output "$Server is uncontactable"
$uncontactable += $Server
}
}
"There are $($contactable.count) contactable Servers"
"There are $($uncontactable.count) uncontactable Servers"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment