Reputation: 143
Below is my PowerShell script. It produces a nicely formatted HTML table. I'd like to make a single column bold (Full % column). I can't for the life of me think of a way to do it.
I've tried inserting bold tags in different places and tried thinking of a way to use replace but since the numbers change in the columns I can't think of a way to do it.
$symmid = 1555
$command1 = symfast -sid $symmid list -association -demand
$command2 = symcfg -sid $symmid list -thin -pool -detail -gb
$basedir = "C:\ts\Scripts"
$timestamp = Get-Date -Format ddMMyyyy
$CSSFile = "$basedir\csstemplate.css"
$css = get-content $CSSFile
$command1 > $basedir\archive_vp\archive_$timestamp.txt
$command2 > $basedir\archive_pool\archive_$timestamp.txt
$regex = '(?ms)P O O L S(.+?)\r\n\s*\r\n'
$command2 = $command2 -join "`r`n"
$command2 = [regex]::Matches($command2,$regex) | foreach {$_.groups[1].value}
$command2 = $command2 -split "`r`n" | select -Skip 5
$command2Format = $command2 | % {
$column = $_ -split ' +'
$hash = [ordered]@{
'Pool Name' = $column[0]
'Flags PTECSL' = $column[1]
'Dev Config' = $column[2]
'Total GBs' = $column[3]
'Usable GBs' = $column[4]
'Free GBs' = $column[5]
'Used GBs' = $column[6]
'Full (%)' = $column[7]
'Subs (%)' = $column[8]
'Comp (%)' = $column[9]
'Shared GBs' = $column[10]
}
New-Object -Type PSCustomObject -Property $hash
} | ConvertTo-Html -Head $a
function get-css
{
foreach($line in $css)
{
$style += $line
}
return $style
}
$style = "<style>"
$style = get-css
$style += "</style>"
$report = "<html><head>$style</head><body>$command2Format</body></html>"
$report | Out-File $basedir\test.html
Invoke-Expression $basedir\test.html
Output:
Upvotes: 0
Views: 1273
Reputation: 46730
You should be able to follow this basic example to get what you are looking for
$a = @"
<style>
TD:nth-child(1){font-weight: bold}
</style>
"@
Get-ChildItem c:\temp -Directory | Select Name,lastwritetime | ConvertTo-Html -Head $a | Set-Content c:\temp\file.html
ii c:\temp\file.html
So as defined by nth-child(1)
the first column of data will have its text bolded. You should be able to accomplish the same thing with the 7th column.
Yes, like Tim Ferrill says, you would need browser support for this but that should not be a tall order.
Upvotes: 1
Reputation: 1674
Can you count on CSS3? If so you can use the :nth-Child()
selector. Details here: http://www.w3schools.com/cssref/sel_nth-child.asp
Upvotes: 2