Updates
recent

How to add multiple contents in a HTML Report using Powershell

Hey Geeks,

Today em gonna show you how to add multiple contents like CPU Utilization, Disk check, Services Check etc. into a single HTML Report file. Few days back I got this requirement to add multiple contents into a single report file and once the report generation is done send a mail.

So lets learn how to achieve this through Powershell.

Powershell provides two properties for this PRECONTENT & POSTCONTENT ,so whatever you want to add should be kept in Pre Content and finally we can merge it using Post Content. Further you can also use Add-Content , Append or Out-File to do the same. But in this example I will show you Pre Content and Post Content.

Sample 1 : How to Add contents 


$Services = gwmi -Class Win32_Service -ComputerName $Server -Credential $Cred |?{$_.name -match ‘Test’} | Select Name,State | Select -last 4 | ConvertTo-HTML -AS Table -Fragment -PreContent ‘<h2>Services Report</h2>’| Out-String


Sample 2 : How to Merge all the contents


ConvertTo-HTML -head $Style -PostContent $Services, $Disk_Report, $SFTP_Table -PreContent ‘<h1><u><center>REPORT GENERATION</u></center></h1>’| Out-File $Report_Path

Output :




Full Sample Script Below :



Copyright © 2016 Amar Helloween. Powered by Blogger.