Solved

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

Posted on 2014-09-15
10
1,273 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 81

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
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 
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 81

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
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.
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…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

739 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