PowerShell Convertto-html格式样式

时间:2014-05-06 16:06:42

标签: html powershell powershell-v2.0 powershell-v3.0

我试图使用以下代码将powershell结果输出到html文件中:

$a = "<style>"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:white}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:white}"
$a = $a + "</style>"

Get-item c:\work | select-object Name,Lastwritetime,@{label="Size" ; expression={[math]::round(((Get-childitem -force "c:\work" -recurse | measure-object length -sum).sum/1Gb),1)}}
get-childitem .....| Convertto-html -head $a | Out-File -append C:\temp\backup.htm
....
....

html文件的结果如下所示:

enter image description here

所以我的问题是:

如何在顶部只有一个Name LastTime Size行以及如何修复表单的长度?

1 个答案:

答案 0 :(得分:1)

每次使用ConvertTo-Html时,都会创建一个新表。这就是宽度不一致的原因。

将表格的所有结果合并为一个变量,然后将其转换为html一次。这将创建一个单独的html表,其中包含一个标题和一致的宽度。