Create HTML System Reports

by May 26, 2010

ConvertTo-HTML is a great way of creating system reports because you can combine information gathered from different sources into one report. The following code will create a report with service information that is gathered from Get-Service, operating system overview returned by WMI, and installed software read directly from the registry:

$style = @'
<style>
body { background-color:#EEEEEE; }
body,table,td,th { font-family:Tahoma; color:Black; Font-Size:10pt }
th { font-weight:bold; background-color:#AAAAAA; }
td { background-color:white; }
</style>
'@

& {
"<HTML><HEAD><TITLE>Inventory Report</TITLE>$style</HEAD>"
"<BODY><h2>Report for '$env:computername'</h2><h3>Services</h3>"
Get-Service |
Sort-Object Status, DisplayName |
ConvertTo-HTML DisplayName, ServiceName, Status -Fragment
'<h3>Operating System Details</h3>'
Get-WMIObject Win32_OperatingSystem |
Select-Object * -exclude __* |
ConvertTo-HTML -as List -Fragment
'<h3>Installed Software</h3>'
Get-ItemProperty Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, InstallDate, DisplayVersion, Language |
Sort-Object DisplayName | ConvertTo-HTML -Fragment
'</BODY></HTML>'
} | Out-File $home\report.hta
ii $home\report.hta

Twitter This Tip! ReTweet this Tip!