繁体   English   中英

html报告中的Powershell输出颜色

[英]Powershell output color in html report

我一直在寻找和测试,但到目前为止没有任何乐趣。 在下面的脚本中 $statFix2 是一个重要的数字。 我试图弄清楚如何在 html 报告中将其字体更改为红色,如果其值高于“10”。 我试过 IF 语句,但不确定把它放在哪里或正确的方法。 有人有想法吗?

谢谢!

$smtp = "5.5.5.5"
$to = "x@x.com"
$from = "y@y.com"
$subject = "Replication Status"
$header = @"
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #B4DFFF;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
</style>
"@

#create report array and foreach loop. This requires a text file with the different consistency group names(case sensitive) in it.
$report = @()
ForEach ($cg in (get-content C:\Scripts\HealthCheckScript\consistencyGroups.txt)){
     $tempCgState = (get-content C:\Scripts\HealthCheckScript\cgState.txt)
     $tempCgStats = (get-content C:\Scripts\HealthCheckScript\cgStats.txt)
     $statFix = $tempCgStats |select-string "WAN traffic"
     $statfix1 = $tempCgStats |Select-String "Current image"
     $statfix2 = $tempCgStats |Select-String "Journal lag"
     $statfix3 = $tempCgState |Select-String "Data Transfer"
     
     $row = "" | Select Consistency_Group, Sync_Status, Transfer_Rate, Journal_Current_Image, Journal_Lag_Status
          $row.Consistency_Group = $cg
          $row.Sync_Status = $statFix3 
          $row.Transfer_Rate = $statFix
          $row.Journal_Current_Image = $statFix1
          $row.Journal_Lag_Status = $statFix2
          $report += $row
}

#create Email body using the report and the html style defined above
$body = $report| ConvertTo-HTML -Head $header |out-string

#send the email
Send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml

继续我的评论......

'powershell 发送 html 颜色'

击中(S)...

在 Powershell 电子邮件中设置 HTML 字体颜色

使用 PowerShell 和零 HTML 知识发送 HTML 电子邮件

$disks = GET-WMIOBJECT win32_logicaldisk -filter "DriveType='3'"

foreach($disk in $disks)
{
$DriveLetter = $disk.DeviceID;
$SizeGB = $disk.Size / 1GB -as [int]
$FreeSpaceGB = $disk.FreeSpace / 1GB -as [int]
$PercentFree = [math]::Round((1- ($freeSpaceGB/ $sizeGB)) * 100)

$dataRow = "
</tr>
<td>$DriveLetter</td>
<td>$SizeGB GB</td>
<td>$FreeSpaceGB GB</td>
<td>$PercentFree %</td>
</tr>
"
$diskreport += $datarow

}

$report = "<html>
<style>
{font-family: Arial; font-size: 13pt;}
TABLE{border: 1px solid black; border-collapse: collapse; font-size:13pt;}
TH{border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;}
TD{border: 1px solid black; padding: 5px; }
</style>
<h2>Server Space Report</h2>
<table>
<tr>
<th>Volume</th>
<th>Total Space</th>
<th>Free Space</th>
<th>Percent Full</th>
</tr>
$diskreport
</table>
<tr>
"

Send-MailMessage -To luke@test.com -From ServerReport@test.com -Body $report -subject "Server Disk Space Report" -SmtpServer mysmtpserver.com

有模块可以使用...

Find-Module -Name '*html*' | Format-Table -AutoSize

# Results
<#
Version  Name              Repository Description                                                                                                                  
-------  ----              ---------- -----------                                                                                                                  
0.0.95   PSWriteHTML       PSGallery  Module that allows creating HTML content/reports in a easy way.                                                              
...
0.1.7    PowerHTML         PSGallery  Provides a wrapper for HTML Agility Pack for use where the IE HTML DOM from Invoke-WebRequest is not available such as Pow...
1.4.1.2  ReportHTML        PSGallery  A powerful module for creating HTML reports within PowerShell no HTML coding required.  For more details on what is possib...
...
0.1.1    HtmlReport        PSGallery  Generate pretty HTML reports with tables and charts                                                                          
1.0.1    Write-HtmlNode    PSGallery  Writes the given HTML node with color.                                                                                       
...
#>

不得不重做脚本,但我发现的唯一有效的解决方案来自这个线程:

根据条件对 HTML 邮件中的单元格进行颜色编码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM