Powershell創(chuàng)建簡潔的HTML報告例子
支持所有版本
把結(jié)果變成復(fù)雜的HTML報告,一個簡單的方法是定義三個腳本塊:一個用作HTML的開頭文檔,一個用作它的結(jié)尾,還有一個是存放動態(tài)對象的表格
接著,把這些腳本塊傳入到ForEach-Object,分別對應(yīng)腳本的開始塊、中間要處理的動態(tài)列表塊和結(jié)束代碼塊。
下面有個簡單的例子闡述如何用它創(chuàng)造一個服務(wù)報告:
$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.fzitv.net/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)文章
PowerShell中使用Out-String命令把對象轉(zhuǎn)換成字符串輸出的例子
這篇文章主要介紹了PowerShell中使用Out-String命令把對象轉(zhuǎn)換成字符串輸出的例子,即把對象轉(zhuǎn)為字符串的方法,需要的朋友可以參考下2014-08-08
Powershell小技巧之獲取當(dāng)前的時間并轉(zhuǎn)換為時辰
這篇文章主要介紹了使用Powershell獲取當(dāng)前的時間并轉(zhuǎn)換為時辰的方法,非常簡單實(shí)用,有需要的朋友可以參考下2014-09-09
PowerShell函數(shù)中限制數(shù)組參數(shù)個數(shù)的例子
這篇文章主要介紹了PowerShell中限制函數(shù)的數(shù)組參數(shù)個數(shù)的例子,可以控制數(shù)組的參數(shù)個數(shù)在指定范圍內(nèi),需要的朋友可以參考下2014-07-07
Windows Powershell 創(chuàng)建數(shù)組
在日常處理中,除了使用像“數(shù)值類型”和“字符串類型”外,還需要使用能夠包含其他對象的“集合”類型。大多數(shù)常見語言,都提供一些操作集合類型的語法。最基本的集合類型就是數(shù)組類型,它提供了一種下標(biāo)基于0的數(shù)組對象。2014-09-09
用PowerShell刪除N天前或指定日期(前后)創(chuàng)建(或修改)的文件
這篇文章主要介紹了用PowerShell刪除N天前或指定日期(前后)創(chuàng)建(或修改)的文件,需要的朋友可以參考下2016-11-11

