Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: General » microsoft.public.windows.powershell
Thread: ping results to html file

HTVi
TV Discussion Newsgroups

ping results to html file
Eero J 12/22/2008 9:44:00 AM
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?
Re: ping results to html file
OldDog <mikef2691[ at ]comcast.net> 12/22/2008 4:47:08 PM
On Dec 22, 3:44 am, Eero J <Eero J...[ at ]discussions.microsoft.com>
wrote:
[Quoted Text]
> 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 way, but it works ( as always,
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 + "
[ at ] " + $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
------------------------------------------------------------->
Re: ping results to html file
OldDog <mikef2691[ at ]comcast.net> 12/22/2008 4:53:20 PM
On Dec 22, 3:44 am, Eero J <Eero J...[ at ]discussions.microsoft.com>
wrote:
[Quoted Text]
> 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 + "
[ at ] " + $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>")}
}
Re: ping results to html file
OldDog <mikef2691[ at ]comcast.net> 12/22/2008 4:54:56 PM
On Dec 22, 3:44 am, Eero J <Eero J...[ at ]discussions.microsoft.com>
wrote:
[Quoted Text]
> 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 + "
[ at ] " + $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>")}
}


Watch the wrap!!!!!
Re: ping results to html file
"Flowering Weeds" <no[ at ]addre.ss> 12/22/2008 7:10:18 PM

[Quoted Text]
>
> The idea is to have a ping monitoring html file,
> where pinging servers are displayed green and
> not pinging servers are displayed red.
>

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.


Re: ping results to html file
Eero J 12/23/2008 8:29:01 AM
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:

[Quoted Text]
> On Dec 22, 3:44 am, Eero J <Eero J...[ at ]discussions.microsoft.com>
> wrote:
> > 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 + "
> [ at ] " + $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>")}
> }
>
Re: ping results to html file
OldDog <mikef2691[ at ]comcast.net> 12/30/2008 6:43:22 PM
On Dec 23, 2:29 am, Eero J <Ee...[ at ]discussions.microsoft.com> wrote:
[Quoted Text]
> 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 Dec 22, 3:44 am, Eero J <Eero J...[ at ]discussions.microsoft.com>
> > wrote:
> > > 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//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 + "
> > [ at ] " + $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>")}
> > }- Hide quoted text -
>
> - Show quoted text -

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

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen