PowerShell Create concise examples of HTML reports _powershell

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.