Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Pinging

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 11-16-2007   #1 (permalink)
PShellNoober
Guest


 

Pinging

I was wondering if there is a way to set a time to ping a certain server.

I'm using the line

Get-WmiObject -Class Win32_PingStatus -Filter "myserver" | Select-Object
-Property Address, ResponseTime

to ping the server once.

So is there a way to run this lets say every 10 minutes?

My System SpecsSystem Spec
Old 11-16-2007   #2 (permalink)
Shay Levi
Guest


 

Re: Pinging

Sure you can. Save your commands into a ps1 file.
Configure new Scheduled task. In the "Run" textbox type:

C:\WINDOWS\system32\WINDOW~1\v1.0\powershell.exe <path to your script.ps1>

On the schedule tab choose to run it "Daily", click advanced, tick the repeat
task checkbox, choose 10 minutes,
tick "duration" and type 24 for "hours" and 0 for "minutes"


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com


Quote:

> I was wondering if there is a way to set a time to ping a certain
> server.
>
> I'm using the line
>
> Get-WmiObject -Class Win32_PingStatus -Filter "myserver" |
> Select-Object -Property Address, ResponseTime
>
> to ping the server once.
>
> So is there a way to run this lets say every 10 minutes?
>

My System SpecsSystem Spec
Old 11-16-2007   #3 (permalink)
Karl Prosser[MVP]
Guest


 

Re: Pinging

if you want the window open and just running forever until you press ctrl+C

have a loop
then after you ping do a start sleep

start-sleep 600


PShellNoober wrote:
Quote:

> I was wondering if there is a way to set a time to ping a certain server.
>
> I'm using the line
>
> Get-WmiObject -Class Win32_PingStatus -Filter "myserver" | Select-Object
> -Property Address, ResponseTime
>
> to ping the server once.
>
> So is there a way to run this lets say every 10 minutes?
My System SpecsSystem Spec
Old 11-16-2007   #4 (permalink)
PShellNoober
Guest


 

Re: Pinging

Awesome, Thank You.

One more question:

If I have a list of servers, can I import that list into the string so it
will ping all the servers in the list? I tried something like this, and it
just prints out the 2 servers I have listed in the .csv

$DC = get-content "C:\test\dc.csv"
Get-WmiObject -Class Win32_PingStatus -Filter "Address='$DC'" | `
Select-Object -Property Address,ResponseTime | export-csv c:\test\ping.csv

I know the import works if I only have one server listed in the file, so I
must be missing something.

Thanks for any help

"Shay Levi" wrote:
Quote:

> Sure you can. Save your commands into a ps1 file.
> Configure new Scheduled task. In the "Run" textbox type:
>
> C:\WINDOWS\system32\WINDOW~1\v1.0\powershell.exe <path to your script.ps1>
>
> On the schedule tab choose to run it "Daily", click advanced, tick the repeat
> task checkbox, choose 10 minutes,
> tick "duration" and type 24 for "hours" and 0 for "minutes"
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
>
>
Quote:

> > I was wondering if there is a way to set a time to ping a certain
> > server.
> >
> > I'm using the line
> >
> > Get-WmiObject -Class Win32_PingStatus -Filter "myserver" |
> > Select-Object -Property Address, ResponseTime
> >
> > to ping the server once.
> >
> > So is there a way to run this lets say every 10 minutes?
> >
>
>
>
My System SpecsSystem Spec
Old 11-16-2007   #5 (permalink)
Thomas Lee
Guest


 

Re: Pinging

In message <8BE81327-92DE-4F6C-8D35-007BF66A3ED7@xxxxxx>,
PShellNoober <PShellNoober@xxxxxx> writes
Quote:

>$DC = get-content "C:\test\dc.csv"
foreach ($comp in $dc) {
Get-WmiObject -Class Win32_PingStatus -Filter "Address='$comp'" | `
Select-Object -Property Address,ResponseTime | `
export-csv c:\test\ping.csv
}
--
Thomas Lee
doctordns@xxxxxx
MVP - Admin Frameworks and Security
My System SpecsSystem Spec
Old 11-16-2007   #6 (permalink)
PShellNoober
Guest


 

Re: Pinging

The loop kind of works, it only prints out the last server in the list. Any
ideas of why it's skipping the first two?

"Thomas Lee" wrote:
Quote:

> In message <8BE81327-92DE-4F6C-8D35-007BF66A3ED7@xxxxxx>,
> PShellNoober <PShellNoober@xxxxxx> writes
Quote:

> >$DC = get-content "C:\test\dc.csv"
>
> foreach ($comp in $dc) {
> Get-WmiObject -Class Win32_PingStatus -Filter "Address='$comp'" | `
> Select-Object -Property Address,ResponseTime | `
> export-csv c:\test\ping.csv
> }
> --
> Thomas Lee
> doctordns@xxxxxx
> MVP - Admin Frameworks and Security
>
My System SpecsSystem Spec
Old 11-16-2007   #7 (permalink)
Shay Levi
Guest


 

Re: Pinging


You can also schedule the task with schtasks.exe:

schtasks /s <computerName> /create /sc minute /mo 10 /tn "PowerShell Script"
/tr "C:\WINDOWS\system32\WINDOW~1\v1.0\powershell.exe c:\scripts\yourScript.ps1"
/ru <username> /rp <password>

More examples can be found here:
http://www.microsoft.com/resources/d....mspx?mfr=true


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com


Quote:

> Sure you can. Save your commands into a ps1 file.
> Configure new Scheduled task. In the "Run" textbox type:
> C:\WINDOWS\system32\WINDOW~1\v1.0\powershell.exe <path to your
> script.ps1>
>
> On the schedule tab choose to run it "Daily", click advanced, tick the
> repeat
> task checkbox, choose 10 minutes,
> tick "duration" and type 24 for "hours" and 0 for "minutes"
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
Quote:

>> I was wondering if there is a way to set a time to ping a certain
>> server.
>>
>> I'm using the line
>>
>> Get-WmiObject -Class Win32_PingStatus -Filter "myserver" |
>> Select-Object -Property Address, ResponseTime
>>
>> to ping the server once.
>>
>> So is there a way to run this lets say every 10 minutes?
>>

My System SpecsSystem Spec
Old 11-16-2007   #8 (permalink)
Shay Levi
Guest


 

Re: Pinging

Thomas,

Keep in mind that the foreach loop will overwrite the csv file each iteration
and eventually
only the last remote machine address and response time will be recorded.
Add-Content will do the job.

foreach ($comp in $dc) {
$ping=Get-WmiObject -query "select Address,ResponseTime from Win32_PingStatus
where Address='$comp'";
add-content c:\test\ping.csv "$($ping.address),$($ping.ResponseTime)";
}


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com


Quote:

> The loop kind of works, it only prints out the last server in the
> list. Any ideas of why it's skipping the first two?
>
> "Thomas Lee" wrote:
>
Quote:

>> In message <8BE81327-92DE-4F6C-8D35-007BF66A3ED7@xxxxxx>,
>> PShellNoober <PShellNoober@xxxxxx> writes
>>
Quote:

>>> $DC = get-content "C:\test\dc.csv"
>>>
>> foreach ($comp in $dc) {
>> Get-WmiObject -Class Win32_PingStatus -Filter "Address='$comp'" | `
>> Select-Object -Property Address,ResponseTime | `
>> export-csv c:\test\ping.csv
>> }
>> --
>> Thomas Lee
>> doctordns@xxxxxx
>> MVP - Admin Frameworks and Security

My System SpecsSystem Spec
Old 11-16-2007   #9 (permalink)
Thomas Lee
Guest


 

Re: Pinging

In message <99713A8E-8CB1-4625-B56C-72399A18801D@xxxxxx>,
PShellNoober <PShellNoober@xxxxxx> writes
Quote:

>The loop kind of works, it only prints out the last server in the list. Any
>ideas of why it's skipping the first two?
Yeah - because each time it goes through the loop, it overwrites
ping.csv. :-(


Quote:

>"Thomas Lee" wrote:
>
Quote:

>> In message <8BE81327-92DE-4F6C-8D35-007BF66A3ED7@xxxxxx>,
>> PShellNoober <PShellNoober@xxxxxx> writes
Quote:

>> >$DC = get-content "C:\test\dc.csv"
>>
>> foreach ($comp in $dc) {
>> Get-WmiObject -Class Win32_PingStatus -Filter "Address='$comp'" | `
>> Select-Object -Property Address,ResponseTime | `
>> export-csv c:\test\ping.csv
>> }
>> --
>> Thomas Lee
>> doctordns@xxxxxx
>> MVP - Admin Frameworks and Security
>>
--
Thomas Lee
doctordns@xxxxxx
MVP - Admin Frameworks and Security
My System SpecsSystem Spec
Old 11-16-2007   #10 (permalink)
Shay Levi
Guest


 

Re: Pinging

You can also use the .net native ping class, you can ping by ip or host name.
Declare $ping outside the loop
and call the send method in each iteration.

PS > $ping = new-object System.Net.NetworkInformation.Ping;
PS > $res=$ping.send("google.com");
PS > $res

Status : Success
Address : 72.14.207.99
RoundtripTime : 179
Options : System.Net.NetworkInformation.PingOptions
Buffer : {97, 98, 99, 100...}


########

$dc = get-content "C:\test\dc.csv"
$ping = new-object System.Net.NetworkInformation.Ping;

foreach ($comp in $dc) {
$res=$ping.send($comp);
add-content c:\test\ping.csv "$($res.address),$($res.Status),$($res.RoundtripTime)";
}



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com


Quote:

> I was wondering if there is a way to set a time to ping a certain
> server.
>
> I'm using the line
>
> Get-WmiObject -Class Win32_PingStatus -Filter "myserver" |
> Select-Object -Property Address, ResponseTime
>
> to ping the server once.
>
> So is there a way to run this lets say every 10 minutes?
>

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Switch the Pinging from IPv6 to Ping IPv4 VistaKing Network & Internet 2 5 Days Ago 02:15 AM
Problem pinging computer on a domain using Vista Business Flip Lewis Vista security 0 05-12-2008 10:49 AM
Pinging one server within the same subnet fails but works in anoth Matt Wilson Vista networking & sharing 9 06-01-2007 10:38 AM
General failure when pinging local nic after Basic to Premium Upgr Jeff Vista General 6 05-13-2007 06:29 PM
Pinging Justin: OT on SRT8 Chargers HEMI-Powered Vista General 4 03-17-2007 06:50 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51