?
Solved

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

Posted on 2014-09-15
10
Medium Priority
?
1,358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 82

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 14

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
 
LVL 12

Expert Comment

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

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 14

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

770 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