Saturday, 7 January 2017

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 |?{$ -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 :

No comments:

Post a Comment

Hyperlinks are not allowed in comments, Spam/advertising comments will NEVER BE TOLERATED and will be deleted immediately!

Thanks for visiting our website,Bookmark us for more updates.

Contact us


Email *

Message *