Solved

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

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

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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 80

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell Active Directory Attribute LVR Metadata 3 19
Powershell to query AD 3 35
Want to Create New-GlobalAddressList 2 13
How to query host with powershell 3 22
Learn about cloud computing and its benefits for small business owners.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
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…

837 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