Difference between revisions of "Powershell to test connectivity"
From MyWiki
(Created page with "<source lang="powershell"> $servers = “dc1″,”dc3″,”sql1″,”wds1″,”ex1″ Foreach($s in $servers) { </source> <source lang="powershell"> if(!(Test-Connecti...") |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | Perform action for a list of servers: | ||
<source lang="powershell"> | <source lang="powershell"> | ||
Line 7: | Line 8: | ||
{ | { | ||
</source> | </source> | ||
+ | If no connection do something: | ||
<source lang="powershell"> | <source lang="powershell"> | ||
Line 12: | 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" } }