Solved Powershell script parsing lines to file

March 29, 2012 at 03:27:43
Specs: Windows 7
Hi,

I have 4 clients in my home. My pc is main computer. I want write the powershell script for control them ping response.

When i start the script from my main pc, script must do these things;

* Ping Ip1 50 times and parse "IP1_Minimum = 57ms, Maximum = 98ms, Average = 68ms" line to d:\test.txt
* Ping Ip2 50 times and parse "IP2_Minimum = 57ms, Maximum = 98ms, Average = 68ms" line to d:\test.txt
* Ping Ip3 50 times and parse "IP3_Minimum = 57ms, Maximum = 98ms, Average = 68ms" line to d:\test.txt
* Wait 5 minutes after 3 process results writing to file is complete and return to top of the process and repeat.

Can someone write this script example ?

Thanks in advance.


See More: Powershell script parsing lines to file

Report •


#1
March 31, 2012 at 14:31:09
✔ Best Answer
PowerShell isn't particularly good at parsing text files. You might want to look into the PowerShell cmdlet Test-Connection to hand the pings for you. It'll give you a better handle of the output, at the very least.

EDIT: I imagine something like this is what you'd want:

while (1) {
  "www.google.com","www.bing.com" | ForEach-Object { $ping = Test-Connection $_ -Count 50 | Measure-Object ResponseTime -Minimum -Maximum -Average
    "Com: {0} Min: {1}, Max: {2}, Avg: {3}" -f $_, $ping.Minimum, $ping.Maximum, $ping.Average >> d:\test.txt
  }
  Start-Sleep -Seconds (5 * 60)
}

How To Ask Questions The Smart Way


Report •

#2
April 1, 2012 at 16:45:50
Hi Razor,

Exactly you are pwershell guru. Thanks for your solution.

Kind Regards.


Report •
Related Solutions


Ask Question