Pergunta

I am trying to output powershell result into html file by using code below:

$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
....
....

The result of html file looks like this:

enter image description here

So my question is:

How to have only one Name LastTime Size row on top and how to fix the length of the form ?

Foi útil?

Solução

Each time you use ConvertTo-Html, you are creating a new table. That's why the widths are not consistent.

Get all of your results for the table into a single variable, then convert it to html once. That will create a single html table, with one header, and consistent widths.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top