欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Powershell創(chuàng)建簡潔的HTML報(bào)告例子

 更新時(shí)間:2014年11月07日 09:38:32   投稿:junjie  
這篇文章主要介紹了Powershell創(chuàng)建簡潔的HTML報(bào)告例子,本文先是講解了實(shí)現(xiàn)的步驟,然后給出了實(shí)現(xiàn)代碼,需要的朋友可以參考下

支持所有版本

把結(jié)果變成復(fù)雜的HTML報(bào)告,一個(gè)簡單的方法是定義三個(gè)腳本塊:一個(gè)用作HTML的開頭文檔,一個(gè)用作它的結(jié)尾,還有一個(gè)是存放動(dòng)態(tài)對(duì)象的表格

接著,把這些腳本塊傳入到ForEach-Object,分別對(duì)應(yīng)腳本的開始?jí)K、中間要處理的動(dòng)態(tài)列表塊和結(jié)束代碼塊。

下面有個(gè)簡單的例子闡述如何用它創(chuàng)造一個(gè)服務(wù)報(bào)告:

復(fù)制代碼 代碼如下:

$path = "$env:temp\report.hta"
 
$beginning = {
 @'
    <html>
    <head>
    <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>
 
    </head>
    <image src="http://www.dbjr.com.cn/yourlogo.gif" />
    <h1>System Report</h1>
    <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>
    </html>
    </body>
'@
 
 
}
 
 
Get-Service |
  ForEach-Object -Begin $beginning -Process $process -End $end |
  Out-File -FilePath $path -Encoding utf8
 
Invoke-Item -Path $path

相關(guān)文章

最新評(píng)論