Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help formatting html output

Status
Not open for further replies.

Dom606

IS-IT--Management
Jul 29, 2007
123
US
I am very new to Powershell. I managaged to create a script and have it execute via a .bat file.

My problem is the output is not very user friendly so I wanted to add some HTML to make the output more easy to read.

The code below shows what I am trying to do but I only get the heading and background color as the output. There is no detail.

Can you please let me know what I am doing wrong. i am using V1.0
Code:
#
#Get System Event Errors except for those liste in $APPevents above
#
$SysEvent = get-EventLog -logname Application -newest 2000 -ComputerName $Servers | where-object {$APPevents -notcontains $_.eventid}
$SysError = $SysEvent |where {$_.entryType -match "Error"}
$APPCSVPath = "C:\z_Application_EventViewerErrors.csv" # The files where Application Events are written to
$SysError | sort TimeWritten  –Descending| `
select TimeWritten, eventid, machinename, entrytype, source, message `
| Export-Csv $APPCSVPath -NoTypeInformation 

[COLOR=#CC0000]Below is where I am running into problems.  
The .csv file is converted to html but I cannot get it to formatt.[/color]

#$html = Import-CSV C:\z_Application_EventViewerErrors.csv | ConvertTo-HTML `
$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$a = $a + "</style>"
$html = Import-CSV C:\z_Application_EventViewerErrors.csv
select TimeWritten, eventid, machinename, entrytype, source, message |
ConvertTo-HTML -head $a -body  "<H2>Application Errors</H2>" | 
Set-Content c:\z_Application_EventViewerErrors.html
 
Never mind. I figured it out.
Code:
$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$a = $a + "</style>"
$html = Import-CSV C:\z_Application_EventViewerErrors.csv |
ConvertTo-HTML TimeWritten,EventID,MachineName,EntryType,Source,Message -body $a "<H2>Application Errors</H2>" | 
Set-Content c:\z_Application_EventViewerErrors.html
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top