HTML Powershell


Good evening from Israel, As you already noticed I often share with you some useful tricks on Powershell.

Today, I am going to show you how to export any query as an HTML file with a background color, table, and further design options.

First of all, In order to retrieve any query/content we have to use the following command:

Get-Process | select name,Cpu,ID | ConvertTo-Html | out-file D:\co.htm

HTML PowerShell

Add Background:

$a = “<style>BODY{background-color:Yellow;}</style>” Get-Process | select name,cpu,ID | ConvertTo-Html -head $a | out-file D:\co.htm

Powershell HTMLAdd Table:

$a = “<style>” $a = $a + “BODY{background-color:peachpuff;}” $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;}” $a = $a + “TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}” $a = $a + “</style>”

HTML Powershell

My suggestion is to use these commands when you generate an email report to any email address, it’s convenient to get designed report

About Meir Peleg 338 Articles
My name is Meir Peleg, (Born 30/04/1991) live in ISRAEL. Live and breath IT world. Microsoft MVP Windows IT & VMware vExpert.