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>")}
> }
>