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