Support all versions
A simple way to turn results into complex HTML reports is to define three script blocks: An opening document for HTML, one to use as its end, and a table to hold a dynamic object.
Next, the script blocks are passed into the foreach-object, corresponding to the start block of the script, the dynamic list block and the end code block to be processed in the middle.
Here's a simple example of how to use it to create a service report:
Copy Code code as follows:
$path = "$env: Temp\report.hta"
$beginning = {
@'
<title>Report</title>
<style type= "Text/css" >
H1 {font-family:segoeui, sans-serif; font-size:20}
th {font-family:segoeui, sans-serif; font-size:15}
TD {Font-family:consolas, Sans-serif; Font-size:12}
</STYLE>
<image src= "Http://www.jb51.net/yourlogo.gif"/>
<table>
<tr><th>Status</th><th>Name</th></tr>
'@
}
$process = {
$status = $_. Status
$name = $_. DisplayName
if ($status-eq ' Running ')
{
' <tr> '
' <td bgcolor= ' #00FF00 >{0}</td> '-F $status
' <td bgcolor= ' #00FF00 >{0}</td> '-F $name
' </tr> '
}
Else
{
' <tr> '
' <td bgcolor= ' #FF0000 >{0}</td> '-F $status
' <td bgcolor= ' #FF0000 >{0}</td> '-F $name
' </tr> '
}
}
$end = {
@'
</table>
</body>
'@
}
Get-service |
Foreach-object-begin $beginning-process $process-end $end |
Out-file-filepath $path-encoding UTF8
Invoke-item-path $path