PowerShell: How to write CSS code for HTML Styling?

Summary

During our PowerShell discussion we assessed many HTML reporting codes. We assesses many basics and advanced codes. Many team members are happy with EnhancedHTML2 module done by Don Jones. So in this Technet Wiki we will show you the quick way of making your CSS code.

Tools

PowerShell ISE
Microsoft Web Expression 4.0

Steps

  • Open MS Web Expression
  • Click File - New - CSS

You can read CSS from this link

Demo


HTML Styles - Get Service


  • HTML body background White
  • Table Header background color Aqua
  • Table Fore Color White
  • High light Table Row colors when user hovers the mouse

CSS Code for HTML Body

body
{
    background-color:white;
    font-family:Tahoma;
    font-size:10px;
}

CSS Code for HTML Table header

th
{
    background-color:aqua;
    color:black;
}

CSS Code for HTML Table Data

td
{
    border:1px solid black;
}

CSS Code for table row hover

tr:hover
{
    background-color:lime;
}

PowerShell Demo Code

$service = Get-Service | Select Name , Displayname , Status | ConvertTo-Html -Fragment            
ConvertTo-Html -Body $service -Title 'Testing Service' -CssUri C:\Temp\STYLE1.CSS | Out-File C:\Temp\Service.html

Output