- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to generate an HTML report using PowerShell?
To generate an HTML report using PowerShell, we can use the ConvertTo-HTML command. For example, let say we need to get the services to report in HTML format then we can use ConvertTo-HTML as a pipeline.
Get-Service | ConvertTo-Html | Out-File C:\Temp\Services.html ii C:\Temp\services.html
The first command will retrieve the output in the HTML file and the second command (ii) is the alias of the Invoke-Item command.
Once you check the output,
It selects all the properties of the command. To select only a few properties, you can either use the Select command or use the -Property parameter in the ConvertTo-Html command. Both the commands are shown below.
Get-Service | Select Name, StartType, Status | ConvertTo-Html | OutFile C:\Temp\services.html
OR,
Get-Service | ConvertTo-Html -Property Name, StartType, Status | OutFile C:\Temp\services.html
Output
You can also use the below parameters to make HTML output more proper.
-Head − To provide the heading.
-PreContent − For the table description.
-PostContent − Description at the bottom.
-Title − Title of the WebPage.
Example,
Get-Service |Select -Last 5| ConvertTo-Html -Property Name, StartType, Status ` -PreContent "<h3>Services Output</h3>" ` -PostContent "<h3>Generated Date: $(Get-Date)/<h3>" ` -Title "Services Information" ` -Head "<h1><center>LocalHost Services Information</center></h1>" ` | Out-File C:\Temp\services.html ii C:\Temp\services.html
Output
If you make the output more stylish, you can apply CSS code as shown below.
Code
$header = @" <style> table, th, td { border-style: solid; border-collapse: collapse; } h3 { color: Blue } <style> "@ Get-Service |Select -Last 5| ConvertTo-Html -Property Name, StartType, Status ` -PreContent "<h3>Services Output</h3>" ` -PostContent "<h3>Generated Date: $(Get-Date)</h3>" ` -Title "Services Information" ` -Head $header ` | Out-File C:\Temp\services.html ii C:\Temp\services.html
Output
- Related Articles
- How to generate multiple reports in HTML using PowerShell?
- How to Generate CLI & JUNIT Newman report on Jenkins using Postman?
- How to generate a strong password using PowerShell?
- How to display multiple outputs on an HTML webpage using PowerShell?
- How to Generate a PDF from an HTML Webpage?
- Generate excel from a report in SAP system
- Creating a Dynamic Report Card using HTML, CSS, and JavaScript
- How to add an attribute to the XML file using Powershell?
- How to generate an array for bi-clustering using Scikit-learn?
- How to traceroute using PowerShell?
- How to send a report through email using Selenium Webdriver?
- How to generate XML using Python?
- How to submit an HTML form using JavaScript?
- How to sort an HTML list using JavaScript?
- How to sort an HTML table using JavaScript?
