PowerShell script to export systeminfo output into a well-formatted HTML report
The Windows systeminfo command provides a wealth of valuable data about system configurations. For IT professionals, this information is essential for audits, documentation, and troubleshooting. To make this data even more accessible and practical, I've created a simple PowerShell script to export systeminfo output into a well-formatted HTML report.
This script transforms the standard systeminfo text output into a clean, structured HTML document. You have all the important system information presented in a readable webpage format, which significantly streamlines tasks like audits, documentation, and information sharing.
The Advantages of HTML Formatting:
Choosing HTML offers distinct benefits for handling system information:
User-Friendly and Efficient
This script is designed to be straightforward and efficient. Running it on any Windows system will generate an HTML file (systeminfo.html) directly in the C:\ drive, containing the system information in an easy-to-read format.
Recommended by LinkedIn
Whether you work in IT support, system administration, or other related fields, having readily accessible and well-presented system information is highly beneficial. This script is designed to facilitate that process.
Explore and Utilize!
Below is the PowerShell script. Feel free to use, modify, and share it as needed.
For your information: The script was thoroughly analyzed using PSScriptAnalyzer for best practices and error-free operation.
# Run the systeminfo command and capture the output
$systemInfoOutput = systeminfo | Out-String
# Convert the output into HTML with CSS for layout
$htmlContent = @"
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f4f4f4;
}
h1 {
color: #333;
text-align: center;
margin-bottom: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
padding: 10px;
border: 1px solid #ccc;
text-align: left;
}
th {
background-color: #f2f2f2;
}
tr:nth-child(even) {
background-color: #fff;
}
tr:nth-child(odd) {
background-color: #f9f9f9;
}
</style>
</head>
<body>
<h1>System Information</h1>
<table>
<thead>
<tr>
<th>Property</th>
<th>Value</th>
</tr>
</thead>
<tbody>
"@
# Process the output to separate properties and values
$lines = $systemInfoOutput -split "`r`n"
foreach ($line in $lines) {
if ($line -match "^(.*?):(.*)") {
$key = $matches[1].Trim()
$value = $matches[2].Trim()
$htmlContent += "<tr><td>$key</td><td>$value</td></tr>"
}
}
$htmlContent += @"
</tbody>
</table>
</body>
</html>
"@
# Specify the HTML file path
$htmlFilePath = "C:\systeminfo.html"
# Save the HTML content to the file
$htmlContent | Out-File -FilePath $htmlFilePath -Encoding utf8
# Display a confirmation message
Write-Output "The HTML file has been saved at the following location : $htmlFilePath"
#PowerShell #SysAdmin #ITAutomation #WindowsTips #TechHacks
IT-Konsulent / IT-Administrator / Infrastruktur-Konsulent
1moLove it, nice and simple. Thanks for sharing.