Link to home
Start Free TrialLog in
Avatar of Frank Helk
Frank HelkFlag for Germany

asked on

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

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 ?
Avatar of Dale Harris
Dale Harris
Flag of United States of America image

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

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
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Frank Helk

ASKER

@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 ....
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

oops didn't see the other answers
perhaps quiet was introduced in a later version of powershell note the older build version
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.
And I'm curious why you only gave one guy credit when I think all of our solutions actually work.
@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.