问题描述
我一直在搜索和测试,但到目前为止还没有喜悦。在以下脚本中,$ statFix2是一个重要数字。我试图弄清楚如何在html报告中将其字体更改为Red,如果其值大于'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
解决方法
继续我的评论...
击中...... p
Setting HTML font color in Powershell email
Sending HTML emails with PowerShell and zero HTML knowledge required
$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.
...
#>
,
必须重做脚本,但是我发现唯一可行的解决方案是从该线程进行: