Solved

Powershell Cmdlet Test-Connection fails on -Quiet .... Why ????

Posted on 2014-09-15
10
1,158 Views
Last Modified: 2014-09-16
Hi friends,

I have a weird problem with Windows Powershell:

Within a script I use the cmdlet Test-Connection to check if a certain station could be pinged successfully. The complete command reads
$pingresult=Test-Connection STATIONX -count 1 -Quiet -ErrorAction SilentlyContinue

With the -Quiet parameter the cmdlet should return a boolean that thells if the station could be reached. On my own station that works well, but on the target station it fails with
Test-Connection : A parameter cannot be found that matches parameter name 'Quiet'.

On my machine (still XP) $PSVersionTable returns
Name                           Value
----                           -----
CLRVersion                     2.0.50727.3655
BuildVersion                   6.0.6002.18111
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1

Open in new window

while on the target machine (Win 2003 Server R2) it returns
Name                           Value                                                                                               
----                           -----                                                                                               
CLRVersion                     2.0.50727.1433                                                                                      
BuildVersion                   6.1.6949.0                                                                                          
PSVersion                      2.0                                                                                                 
PSCompatibleVersions           {1.0, 2.0}    

Open in new window

Unfortunately I need the "Parameter Set: Quiet" because the other parameter sets return complex object that I don't want to parse. The online help (i.e. at MS Technet) doesn't mention anything where -Quiet isn't supported ....

What's wrong here ?
0
Comment
Question by:frankhelk
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 16

Expert Comment

by:Dale Harris
ID: 40322831
If you're doing -Quiet why do you need -erroraction?

Try -count 2 as well, so it gives it 2 chances.

Personally, I would set up something like this:
if (test-connection $server -count 2 -quiet){
#Do something
}

Open in new window

0
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 40322888
I would just try

$pingresult=Test-Connection STATIONX 

Open in new window


check whether the above succeeds first

and then
$pingresult=Test-Connection STATIONX -Quiet

Open in new window


Count defaults to 4 so I wouldn't bother setting my own count
0
 
LVL 78

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 40322939
if you just need a true or false return then


$computer =$env:COMPUTERNAME
if (( test-connection -ComputerName $computer -ErrorAction SilentlyContinue -Count 2)){ Write-Host "Connected" }
else  { Write-Host "Failed"}

Open in new window

0
 
LVL 13

Author Closing Comment

by:frankhelk
ID: 40323039
@Dale Harris:
>If you're doing -Quiet why do you need -erroraction?

Because I don't need any entries in the eventlog, etc. - I only need to know if the station is reachable. true or false. And be as quiet as possible.

@trinitrotoluene:
>I would just try
>     $pingresult=Test-Connection STATIONX

That would not return a boolean but a bunch of ping result objects (4 of them if I don't use "-Count 1"). As told above, I only need a boolean result, which seems to require require "-Quiet".

@David Johnson
>if you just need a true or false return then (...)

Thanks - that seems to provide a workaround for where -Quiet is not supported. Thanks

@anybody out there:
I still want to know WHY the parameter -Quiet is not supported on that station ....
0
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 40323061
this worked for me. just move around the params

if(!(Test-Connection -Cn STATIONX -BufferSize 16 -Count 1 -ea 0 -quiet))
      {"Ping test failed"}
ELSE {"Conn Test succeeded"} #end if

Open in new window

0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 40323065
oops didn't see the other answers
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 40323138
perhaps quiet was introduced in a later version of powershell note the older build version
0
 
LVL 16

Expert Comment

by:Dale Harris
ID: 40323238
This question is closed, but I would like to submit that you don't need an erroraction.  It will be true/false, and an error shouldn't happen because the system will be either online or not.
0
 
LVL 16

Expert Comment

by:Dale Harris
ID: 40323240
And I'm curious why you only gave one guy credit when I think all of our solutions actually work.
0
 
LVL 13

Author Comment

by:frankhelk
ID: 40324854
@David Johnson:
Interestingly, the build of my machine (where -Quiet works) is 6.0.6002.18111, while on the target machine (where it fails), the build is 6.1.6949.0 ... which I presume to be later.

@Dale Harris:
Sorry, but at the time I accepted the soultion, there were 2 anwers not really fitting my problem (-Quiet not working on one system) and one with an acceptable workaround. I seems to be just to accept that answer ... maybe I've been a little fast, but that's life, I think.

Thanks to all for commenting, anyhow.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
A procedure for exporting installed hotfix details of remote computers using powershell
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now