Creating beautiful Powershell Reports in HTML-Format

Powershell Script

Actually SharePoint Admins do a lot stuff with Powershell Scripts. Often in Powershell you get lists where data is collected in table format. Interesting for repeating Scripts you run should be the possibility to create Powershell Reports. Those Powershell based Reports are easy to create if you know how. You also can create a unique .css file to make the design for all reports identically.

Creating Powershell Reports

So if you like this idea, then you should read further more. There are a lot of posts to that topic and i started with a simple CSS file which i later used as a reference in my Powershell Script to format the output Table in the Report. The report itself is a html file. As SharePoint Admin it might be an idea, to create those reports regularly and publish it to a document library or a page, where you can see it from your desktop after update.

Create CSS File

Creating the css file with name PSHtmlReport.css as a reference for later.



table
{
Margin: 0px 0px 0px 4px;
Border: 1px solid rgb(190, 190, 190);
Font-Family: Tahoma;
Font-Size: 8pt;
Background-Color: rgb(252, 252, 252);
}
tr:hover td
{
Background-Color: rgb(0, 127, 195);
Color: rgb(255, 255, 255);
}
tr:nth-child(even)
{
Background-Color: rgb(110, 122, 130);
}
th
{
Text-Align: Left;
Color: rgb(150, 150, 220);
Padding: 1px 4px 1px 4px;
}
td
{
Vertical-Align: Top;
Padding: 1px 4px 1px 4px;
}


I prepared three options in which i show you how you can create your report. I used some sample data which was easy to fetch up. But it’s up to you, to get your data.

Option 1 – Simple Table with CSS



#Option 1 Simple Powershell Report
Get-Process | Select -First 5 | ConvertTo-Html -CSSUri "HtmlReport.css" | Set-Content "HtmlReportOption1.html"


Powershell Reports

Option 2 – Table with Title



#Option 2 with Title
$data = Get-Process | Select -First 5;
$datum = Get-Date -Format "dd.MM.yyyy, HH:mm"
$data | ConvertTo-Html -Title "Report Prozesse" -PreContent "<h1>Report erzeugt von $env:USERNAME am $datum</h1>" -CSSUri "HtmlReport.css" | Set-Content "HtmlReportOption2.html"


Powershell Reports

Option 3 – Multiple Tables in one Powershell Report



#Option 3 multiple Tables in one Powershell Report

$a = Get-Process | Select -First 5 | ConvertTo-HTML -Title "Report Prozesse" -PreContent "<h1>Report Process</h1>"
$b = Get-Service | Select -First 5 | ConvertTo-HTML -Title "Report Service" -PreContent "<h1>Report Service</h1>"
$c = Get-WmiObject -class Win32_OperatingSystem | Select -First 5 | ConvertTo-HTML -Property * -Title "Report OS" -PreContent "<h1>Report OS</h1>"

ConvertTo-HTML -body "$a $b $c" -CSSUri "HtmlReport.css" | Set-Content "HtmlReportOption3.html"


Powershell Reports

 

Summary

Great options to create reports based on information you have and maybe get already regularly. Try it yourself! I can imagine that you can use it, to monitor your SharePoint Farm and generate Powershell Reports from this.

Related Resources:

[1] http://www.itprotoday.com/management-mobility/making-html-reports-powershell
[2] Webcast Plural Sight
[3] https://www.sepago.de/blog/2014/01/20/powershell-daten-als-html-report-ausgeben

 

 

The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.



Karsten Schneider
About Karsten Schneider 278 Articles
He is Consultant for SharePoint Solutions for collaboration, communication and business processes. He provides his customers applications based on standard features as well as development or combining the power of several microsoft tools like Dynamics CRM. In his free time he tries to collect tipps and worthy experience in this blog.

Be the first to comment

Leave a Reply

Your email address will not be published.


*