Created
September 7, 2017 09:48
-
-
Save dtrac/23f584582877dc3f6208aaa9f031f768 to your computer and use it in GitHub Desktop.
Test Server Connections and Create 2x Arrays
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
$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