Difference between revisions of "Powershell to test connectivity"
From MyWiki
| (One intermediate revision by the same user not shown) | |||
| Line 14: | Line 14: | ||
{ | { | ||
| + | </source> | ||
| + | Combine the two above: | ||
| + | <source lang="powershell"> | ||
| + | |||
| + | $servers = “dc1″,”dc3″,”sql1″,”wds1″,”ex1″ | ||
| + | Foreach($s in $servers) | ||
| + | |||
| + | { | ||
| + | |||
| + | if(!(Test-Connection -Cn $s -BufferSize 16 -Count 1 -ea 0 -quiet)) | ||
| + | { | ||
| + | Write-Host "testiing server $s" | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
</source> | </source> | ||
Latest revision as of 09:19, 15 June 2016
Perform action for a list of servers:
$servers = “dc1″,”dc3″,”sql1″,”wds1″,”ex1″ Foreach($s in $servers) {
If no connection do something:
if(!(Test-Connection -Cn $s -BufferSize 16 -Count 1 -ea 0 -quiet)) {
Combine the two above:
$servers = “dc1″,”dc3″,”sql1″,”wds1″,”ex1″ Foreach($s in $servers) { if(!(Test-Connection -Cn $s -BufferSize 16 -Count 1 -ea 0 -quiet)) { Write-Host "testiing server $s" } }