![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | ping results to html file I have a list of servers in my MachineList.txt file. I want to get the result of this script to go to html file. The idea is to have a ping monitoring html file, where pinging servers are displayed green and not pinging servers are displayed red. Here is my script: Clear $PingMachines = Gc "C:\MachineList.txt" ForEach($MachineName In $PingMachines) {$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" | Select-Object StatusCode If ($PingStatus.StatusCode -eq 0) {Write-Host $MachineName -Fore "Green"} Else {Write-Host $MachineName -Fore "Red"}} Could i implement something like this somewhere in the script?: {$MachineName | Convertto-Html > C:\PingResults.htm}} Ho would the correct script look like? |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: ping results to html file On Dec 22, 3:44*am, Eero J <Eero J...@xxxxxx> wrote: Quote: > I have a list of servers in my MachineList.txt file. > I want to get the result of this script to go to html file. > The idea is to have a ping monitoring html file, where pinging servers are > displayed green and not pinging servers are displayed red. > Here is my script: > > Clear > > $PingMachines = Gc "C:\MachineList.txt" > ForEach($MachineName In $PingMachines) > {$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" | > Select-Object StatusCode > If ($PingStatus.StatusCode -eq 0) > {Write-Host $MachineName -Fore "Green"} > Else > {Write-Host $MachineName -Fore "Red"}} > > Could i implement something like this somewhere in the script?: > {$MachineName | Convertto-Html > C:\PingResults.htm}} > Ho would the correct script look like? watch the wrap); Different colors to try: # Red = #FF0000 # Green = #00FF00 # Blue = #0000FF # Cyan (blue and green) = #00FFFF # Magenta (red and blue) = #FF00FF # Yellow (red and green) = #FFFF00 # <--------------- Start script -------------------------------------------------> clear $pingResults =("C:\Scripts\PingResults\PingResults.HTM") # <-- you need to change this $RunDate = (get-date).tostring("MM_dd_yyyy") $PingTime = (Get-Date -format 'hh:mm') #Write the preamble of the report Add-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") Add-Content -Path $pingResults ("<html> <p>") Add-Content -Path $pingResults ("<head> <p>") Add-Content -Path $pingResults ("<title> Ping Results </title>") Add-Content -Path $pingResults ("</head>") Add-Content -Path $pingResults ("<h3>Report Generated " + $RunDate + " @ " + $PingTime + "</h3> <p>") $PingMachines = Gc "C:\MachineList.txt" ForEach($MachineName In $PingMachines) {$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" | Select-Object StatusCode If ($PingStatus.StatusCode -eq 0) {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color = #00FF00>" + $MachineName + "</FONT></h1></pre><br>")} Else {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color = #FF0000>" + $MachineName + "</FONT></h1></pre><br>") Add-Content -Path $pingResults ("<p><br>")} } # <-------------------------- End Script -------------------------------------------------------------> |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: ping results to html file On Dec 22, 3:44*am, Eero J <Eero J...@xxxxxx> wrote: Quote: > I have a list of servers in my MachineList.txt file. > I want to get the result of this script to go to html file. > The idea is to have a ping monitoring html file, where pinging servers are > displayed green and not pinging servers are displayed red. > Here is my script: > > Clear > > $PingMachines = Gc "C:\MachineList.txt" > ForEach($MachineName In $PingMachines) > {$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" | > Select-Object StatusCode > If ($PingStatus.StatusCode -eq 0) > {Write-Host $MachineName -Fore "Green"} > Else > {Write-Host $MachineName -Fore "Red"}} > > Could i implement something like this somewhere in the script?: > {$MachineName | Convertto-Html > C:\PingResults.htm}} > Ho would the correct script look like? # Red = #FF0000 # Green = #00FF00 # Blue = #0000FF # Cyan (blue and green) = #00FFFF # Magenta (red and blue) = #FF00FF # Yellow (red and green) = #FFFF00 clear $pingResults =("C:\Scripts\PingResults\pingResults.HTM") $RunDate = (get-date).tostring("MM_dd_yyyy") $PingTime = (Get-Date -format 'hh:mm') #Write the preamble of the report Add-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") Add-Content -Path $pingResults ("<html> <p>") Add-Content -Path $pingResults ("<head> <p>") Add-Content -Path $pingResults ("<title> Ping Results </title>") Add-Content -Path $pingResults ("</head>") Add-Content -Path $pingResults ("<h3>Report Generated " + $RunDate + " @ " + $PingTime + "</h3> <p>") $PingMachines = Gc "C:\MachineList.txt" ForEach($MachineName In $PingMachines) {$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" | Select-Object StatusCode If ($PingStatus.StatusCode -eq 0) {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color = #00FF00>" + $MachineName + "</FONT></h3></pre><br>")} Else {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color = #FF0000>" + $MachineName + "</FONT></h3></pre><br>") Add-Content -Path $pingResults ("<p><br>")} } |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: ping results to html file Quote: > > The idea is to have a ping monitoring html file, > where pinging servers are displayed green and > not pinging servers are displayed red. > The .NET Framework classes now has charting! This means one can have real-time (war room) charting (in one's html files or Windows Form or WPF or Silverlight or etc.) charting the data one gets from the Windows admin's automation tool, powershell.exe. Just load (like loading any .NET based assembly) System.Windows.Forms.DataVisualization and then make chart after chart after chart! For more help, ask any PowerShell user or MVP or any Microsoft Chart Control user or MVP. |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: ping results to html file Thank you very much for an excellent re-work with this script. One more question. I would like the html to be overwrited everytime the script activates. Meaning that only the latest ping result will be displayed in HTM file. How could this be done? "OldDog" wrote: Quote: > On Dec 22, 3:44 am, Eero J <Eero J...@xxxxxx> > wrote: Quote: > > I have a list of servers in my MachineList.txt file. > > I want to get the result of this script to go to html file. > > The idea is to have a ping monitoring html file, where pinging servers are > > displayed green and not pinging servers are displayed red. > > Here is my script: > > > > Clear > > > > $PingMachines = Gc "C:\MachineList.txt" > > ForEach($MachineName In $PingMachines) > > {$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" | > > Select-Object StatusCode > > If ($PingStatus.StatusCode -eq 0) > > {Write-Host $MachineName -Fore "Green"} > > Else > > {Write-Host $MachineName -Fore "Red"}} > > > > Could i implement something like this somewhere in the script?: > > {$MachineName | Convertto-Html > C:\PingResults.htm}} > > Ho would the correct script look like? > This might not be the most elegant, but it works; > > # Red = #FF0000 > # Green = #00FF00 > # Blue = #0000FF > # Cyan (blue and green) = #00FFFF > # Magenta (red and blue) = #FF00FF > # Yellow (red and green) = #FFFF00 > > clear > $pingResults =("C:\Scripts\PingResults\pingResults.HTM") > $RunDate = (get-date).tostring("MM_dd_yyyy") > $PingTime = (Get-Date -format 'hh:mm') > > #Write the preamble of the report > Add-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD > HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") > Add-Content -Path $pingResults ("<html> <p>") > Add-Content -Path $pingResults ("<head> <p>") > Add-Content -Path $pingResults ("<title> Ping Results </title>") > Add-Content -Path $pingResults ("</head>") > Add-Content -Path $pingResults ("<h3>Report Generated " + $RunDate + " > @ " + $PingTime + "</h3> <p>") > > > $PingMachines = Gc "C:\MachineList.txt" > ForEach($MachineName In $PingMachines) > {$PingStatus = Gwmi Win32_PingStatus -Filter "Address = > '$MachineName'" | > Select-Object StatusCode > If ($PingStatus.StatusCode -eq 0) > {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color = > #00FF00>" + $MachineName + "</FONT></h3></pre><br>")} > Else > {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color = > #FF0000>" + $MachineName + "</FONT></h3></pre><br>") > Add-Content -Path $pingResults ("<p><br>")} > } > |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: ping results to html file On Dec 23, 2:29*am, Eero J <Ee...@xxxxxx> wrote: Quote: > Thank you very much for an excellent re-work with this script. > One more question. I would like the html to be overwrited everytime the > script activates. Meaning that only the latest ping result will be displayed > in HTM file. > How could this be done? > > > > "OldDog" wrote: Quote: > > On Dec 22, 3:44 am, Eero J <Eero J...@xxxxxx> > > wrote: Quote: > > > I have a list of servers in my MachineList.txt file. > > > I want to get the result of this script to go to html file. > > > The idea is to have a ping monitoring html file, where pinging servers are > > > displayed green and not pinging servers are displayed red. > > > Here is my script: Quote: Quote: > > > Clear Quote: Quote: > > > $PingMachines = Gc "C:\MachineList.txt" > > > ForEach($MachineName In $PingMachines) > > > {$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" | > > > Select-Object StatusCode > > > If ($PingStatus.StatusCode -eq 0) > > > {Write-Host $MachineName -Fore "Green"} > > > Else > > > {Write-Host $MachineName -Fore "Red"}} Quote: Quote: > > > Could i implement something like this somewhere in the script?: > > > {$MachineName | Convertto-Html > C:\PingResults.htm}} > > > Ho would the correct script look like? Quote: > > This might not be the most elegant, but it works; Quote: > > # Red = #FF0000 > > # Green = #00FF00 > > # Blue = #0000FF > > # Cyan (blue and green) = #00FFFF > > # Magenta (red and blue) = #FF00FF > > # Yellow (red and green) = #FFFF00 Quote: > > clear > > $pingResults =("C:\Scripts\PingResults\pingResults.HTM") > > $RunDate *= (get-date).tostring("MM_dd_yyyy") > > $PingTime = (Get-Date -format 'hh:mm') Quote: > > #Write the preamble of the report > > Add-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD > > HTML 4.0//ENhttp://www.w3.org/TR/REC-html40/strict.dtd>") > > Add-Content -Path $pingResults ("<html> <p>") > > Add-Content -Path $pingResults ("<head> <p>") > > Add-Content -Path $pingResults ("<title> Ping Results </title>") > > Add-Content -Path $pingResults ("</head>") > > Add-Content -Path $pingResults ("<h3>Report Generated " + $RunDate + " > > @ " + $PingTime + "</h3> <p>") Quote: > > $PingMachines = Gc "C:\MachineList.txt" > > ForEach($MachineName In $PingMachines) > > {$PingStatus = Gwmi Win32_PingStatus -Filter "Address = > > '$MachineName'" | > > Select-Object StatusCode > > If ($PingStatus.StatusCode -eq 0) > > {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color = > > #00FF00>" + $MachineName + "</FONT></h3></pre><br>")} > > Else > > {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color = > > #FF0000>" + $MachineName + "</FONT></h3></pre><br>") > > Add-Content -Path $pingResults ("<p><br>")} > > }- Hide quoted text - > - Show quoted text - Add-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") To this: Set-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") |
My System Specs![]() |
| | #7 (permalink) |
| Guest | Script error When I attempted to run this script, I got the following error: Unexpected token '(' in expression or statement. At :line:2 char:19 + $pingResults =3D (" <<<< C:\temp\pingResults.HTM") All I did was change the path from this: C:\Scripts\PingResults\pingResults.HTM to this: C:\temp\pingResults.HTM Where I created a temp folder. Can you tell why this script is not working for me? Here is the full script copied from the post above. clear $pingResults =3D ("C:\temp\pingResults.HTM") $RunDate =3D (get-date).tostring("MM_dd_yyyy") $PingTime =3D (Get-Date -format 'hh:mm') Add-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") Add-Content -Path $pingResults (" <p>") Add-Content -Path $pingResults ("<head> <p>") Add-Content -Path $pingResults ("<title> Ping Results </title>") Add-Content -Path $pingResults ("</head>") Add-Content -Path $pingResults ("<h3>Report Generated " + $RunDate + " @ " + $PingTime + "</h3> <p>") $PingMachines =3D Gc "C:\MachineList.txt" ForEach($MachineName In $PingMachines) {$PingStatus =3D Gwmi Win32_PingStatus -Filter "Address =3D '$MachineName'" | Select-Object StatusCode If ($PingStatus.StatusCode -eq 0) {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color =3D Else {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color =3D Add-Content -Path $pingResults ("<p><br>")} } Thanks. OldDog wrote: Re: ping results to html file 02-Jan-09 On Dec 23, 2:29=A0am, Eero J <Ee...@newsgroup> wrote: yed s are Name'" | Change this line: Add-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") To this: Set-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") Previous Posts In This Thread: On Monday, December 22, 2008 4:44 AM Eero wrote: ping results to html file I have a list of servers in my MachineList.txt file. I want to get the result of this script to go to html file. The idea is to have a ping monitoring html file, where pinging servers are displayed green and not pinging servers are displayed red. Here is my script: Clear $PingMachines = Gc "C:\MachineList.txt" ForEach($MachineName In $PingMachines) {$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" | Select-Object StatusCode If ($PingStatus.StatusCode -eq 0) {Write-Host $MachineName -Fore "Green"} Else {Write-Host $MachineName -Fore "Red"}} Could i implement something like this somewhere in the script?: {$MachineName | Convertto-Html > C:\PingResults.htm}} Ho would the correct script look like? On Monday, December 22, 2008 2:10 PM Flowering Weeds wrote: FYIThe .NET Framework classes now has charting! FYI The .NET Framework classes now has charting! This means one can have real-time (war room) charting (in one's html files or Windows Form or WPF or Silverlight or etc.) charting the data one gets from the Windows admin's automation tool, powershell.exe. Just load (like loading any .NET based assembly) System.Windows.Forms.DataVisualization and then make chart after chart after chart! For more help, ask any PowerShell user or MVP or any Microsoft Chart Control user or MVP. On Monday, December 22, 2008 9:10 PM OldDog wrote: Re: ping results to html file On Dec 22, 3:44=A0am, Eero J <Eero J...@newsgroup> wrote: e '" | This might not be the most elegant way, but it works ( as always, watch the wrap); Different colors to try: -------------------------------------------------> clear $pingResults =3D("C:\Scripts\PingResults\PingResults.HTM") # <-- you need to change this $RunDate =3D (get-date).tostring("MM_dd_yyyy") $PingTime =3D (Get-Date -format 'hh:mm') Add-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") Add-Content -Path $pingResults ("<html> <p>") Add-Content -Path $pingResults ("<head> <p>") Add-Content -Path $pingResults ("<title> Ping Results </title>") Add-Content -Path $pingResults ("</head>") Add-Content -Path $pingResults ("<h3>Report Generated " + $RunDate + " @ " + $PingTime + "</h3> <p>") $PingMachines =3D Gc "C:\MachineList.txt" ForEach($MachineName In $PingMachines) {$PingStatus =3D Gwmi Win32_PingStatus -Filter "Address =3D '$MachineName'" | Select-Object StatusCode If ($PingStatus.StatusCode -eq 0) {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color =3D Else {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color =3D Add-Content -Path $pingResults ("<p><br>")} } -------------------------------------------------------------> On Monday, December 22, 2008 9:10 PM OldDog wrote: Re: ping results to html file On Dec 22, 3:44=A0am, Eero J <Eero J...@newsgroup> wrote: e '" | This might not be the most elegant, but it works; clear $pingResults =3D("C:\Scripts\PingResults\pingResults.HTM") $RunDate =3D (get-date).tostring("MM_dd_yyyy") $PingTime =3D (Get-Date -format 'hh:mm') Add-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") Add-Content -Path $pingResults ("<html> <p>") Add-Content -Path $pingResults ("<head> <p>") Add-Content -Path $pingResults ("<title> Ping Results </title>") Add-Content -Path $pingResults ("</head>") Add-Content -Path $pingResults ("<h3>Report Generated " + $RunDate + " @ " + $PingTime + "</h3> <p>") $PingMachines =3D Gc "C:\MachineList.txt" ForEach($MachineName In $PingMachines) {$PingStatus =3D Gwmi Win32_PingStatus -Filter "Address =3D '$MachineName'" | Select-Object StatusCode If ($PingStatus.StatusCode -eq 0) {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color =3D Else {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color =3D Add-Content -Path $pingResults ("<p><br>")} } On Monday, December 22, 2008 9:10 PM OldDog wrote: Re: ping results to html file On Dec 22, 3:44=A0am, Eero J <Eero J...@newsgroup> wrote: e '" | clear $pingResults =3D("C:\Scripts\PingResults\pingResults.HTM") $RunDate =3D (get-date).tostring("MM_dd_yyyy") $PingTime =3D (Get-Date -format 'hh:mm') Add-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") Add-Content -Path $pingResults ("<html> <p>") Add-Content -Path $pingResults ("<head> <p>") Add-Content -Path $pingResults ("<title> Ping Results </title>") Add-Content -Path $pingResults ("</head>") Add-Content -Path $pingResults ("<h3>Report Generated " + $RunDate + " @ " + $PingTime + "</h3> <p>") $PingMachines =3D Gc "C:\MachineList.txt" ForEach($MachineName In $PingMachines) {$PingStatus =3D Gwmi Win32_PingStatus -Filter "Address =3D '$MachineName'" | Select-Object StatusCode If ($PingStatus.StatusCode -eq 0) {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color =3D Else {Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color =3D Add-Content -Path $pingResults ("<p><br>")} } Watch the wrap!!!!! On Tuesday, December 23, 2008 3:29 AM Eero wrote: Thank you very much for an excellent re-work with this script. Thank you very much for an excellent re-work with this script. One more question. I would like the html to be overwrited everytime the script activates. Meaning that only the latest ping result will be displayed in HTM file. How could this be done? "OldDog" wrote: On Friday, January 02, 2009 1:05 AM OldDog wrote: Re: ping results to html file On Dec 23, 2:29=A0am, Eero J <Ee...@newsgroup> wrote: yed s are Name'" | Change this line: Add-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") To this: Set-Content -Path $pingResults ("<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd>") EggHeadCafe - Software Developer Portal of Choice Excel Sort Command And Named Range Scramble Prevention http://www.eggheadcafe.com/tutorials...nd-and-na.aspx |
My System Specs![]() |
| | #8 (permalink) |
| Guest | Re: Script error When you copy and pasted the example, I think a bunch of characters got included by mistake... Marco "Ed Crosby" wrote in message news:20091026162029ed@newsgroup Quote: > When I attempted to run this script, I got the following error: > > Unexpected token '(' in expression or statement. > At :line:2 char:19 > + $pingResults =3D (" <<<< C:\temp\pingResults.HTM") |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| export results to tab-delimited file | PowerShell | |||
| How to delete temporary internet html files from search results. | Vista General | |||
| Paginate results of an FSO file list | VB Script | |||
| Change attachment file to html file | Vista performance & maintenance | |||
| uploading script results to a csv file | PowerShell | |||