Powershell脚本转换为html并根据数字阈值更改字体/单元格颜色

问题描述 投票:0回答:1

我有一个简单的powershell脚本,该脚本针对获取cpu,磁盘和mem计数器的服务器列表运行多个查询。我在导入csv时将其填充并转换为html ..也使用脚本中的css来为行着色,但是如果它高于80或低于5,我想突出显示并使用红色的单元格或文本。这是代码的CSS部分,并导入CSV。

$css = @"
<style>
h1, h5, th { text-align: center; font-family: Segoe UI; }
table { margin: auto; font-family: Segoe UI; box-shadow: 10px 10px 5px #888; border: thin ridge grey; }
th { background: #0046c3; color: #fff; max-width: 400px; padding: 5px 10px; }
td { font-size: 11px; padding: 5px 20px; color: #000; }
tr { background: #b8d1f3; }
tr:nth-child(even){ background: #dae5f4; }
</style>
"@

Import-CSV "health.csv" | ConvertTo-Html -Head $css -Body "<h1>Email Report</h1>`n<h5>Generated on $(Get-Date)</h5>" | Out-File "health.html"

使用转换为html时可以吗?

这里是CSV的示例

"Server","CPU","MemFreeGB","CFreeGB","FFreeGB"
server1, 14.72, 17.18, 52.79, 80.42
server2, 0.2, 28.95, 59.86, 77.15
server3, 30.23, 13.5, 54.47, 83.14

我有一个简单的powershell脚本,该脚本针对获取cpu,磁盘和mem计数器的服务器列表运行多个查询。我在导入csv时将其导入并转换为html ..也使用...

html css powershell
1个回答
0
投票

代替使用ConvertTo-Html cmdlet,在这种情况下,您可以使用专用的自定义函数来创建html表,该表允许您向单元格添加额外的样式。

© www.soinside.com 2019 - 2024. All rights reserved.