Change the time out for the Ping

I am using the powershell  to perform ping test.  Below is the script. I want to increase the timeout to 10 seconds from 3 seconds.  Is it that I need to change the 'timeout=3000' to 'timeout=10000'?
Function PingComp([string]$sComp) {
  $vRet = Get-WmiObject -Query "Select * From Win32_PingStatus Where Address = '$sComp' and timeout=3000"

  if ($vRet) {
    if ($vRet.StatusCode -eq 0) {
      LogMessage "${sComp}|Computer responded|$($vRet.ResponseTime) ms"
    } else {
      LogMessage "${sComp}|Computer did not respond"
    }
  } else{
    LogMessage "${sComp}|ERROR|Null value returned"
  }
}

Open in new window

tommym121Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joe Winograd, Fellow&MVEDeveloperCommented:
I don't know if the script actually works, but I can tell you that the timeout param is in milliseconds:

1000 milliseconds = 1 second
3000 milliseconds = 3 seconds
10000 milliseconds = 10 seconds
etc.

So, you are correct! Regards, Joe
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shaun VermaakTechnical Specialist/DeveloperCommented:
Yes
PingComp.png
1
gd6627Commented:
Where do I define the server ?
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Shaun VermaakTechnical Specialist/DeveloperCommented:
PingComp is a function. Run the script then you will have PingComp loaded

After that run
PingComp SomeServer

Open in new window

0
gd6627Commented:
This is what I get?

Function PingComp([string]$sComp) {
  $vRet = Get-WmiObject -Query "Select * From Win32_PingStatus Where Address = '$sComp' and timeout=3000"

  if ($vRet) {
    if ($vRet.StatusCode -eq 0) {
      LogMessage "${sComp}|Computer responded|$($vRet.ResponseTime) ms"
    } else {
      LogMessage "${sComp}|Computer did not respond"
    }
  } else{
    LogMessage "${sComp}|ERROR|Null value returned"
  }
}
pingComp OAk-dc-v01
LogMessage : The term 'LogMessage' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:6 char:7
+       LogMessage "${sComp}|Computer responded|$($vRet.ResponseTime) m ...
+       ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (LogMessage:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundExceptions is what I get ?
0
Joe Winograd, Fellow&MVEDeveloperCommented:
The original question is: "I want to increase the timeout to 10 seconds from 3 seconds. Is it that I need to change the 'timeout=3000' to 'timeout=10000'?"

The answer to that is yes, since the timeout parameter is in milliseconds, and the first post answers it, worthy as the Accepted Solution. The second post shows a test run of the script and is very helpful, worthy as an Assisted Solution. Splitting the points evenly between those two experts. Follow-on questions are not by the OP, so not including comments about them as solutions.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.