TechOnTip Weblog

Run book for Technocrats

Archive for January, 2015

Powershell# HTML Report with Multiple Tables

Posted by Brajesh Panda on January 8, 2015

## ConvertTo-Html –Fragment is used.

## Reference

## Execution ## save the script as html-fragment.ps1 and run as “.\html-fragment.ps1 > html-fragment.htm”

$computername Read-Host “Type computername”

function Get-CSInfo {


$os Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computername

$cs =Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computername

$bios =Get-WmiObject -Class Win32_BIOS -ComputerName $computername

$props = @{


‘OS Version’=$os.version

‘OS Build’=$os.buildnumber

‘Service Pack’=$os.sevicepackmajorversion



‘BIOS Serial’=$bios.serialnumber }

$obj New-Object -TypeName PSObject -Property $props

Write-Output $obj


$frag1 Get-CSInfo –computername $computername ConvertTo-Html -As LIST -Fragment -PreContent ‘<h2>Computer Info</h2>’

$frag2 Get-WmiObject -Class Win32_LogicalDisk -Filter ‘DriveType=3’ -ComputerName $computername Select DeviceID, Freespace, Size
ConvertTo-Html -Fragment -PreContent ‘<h2>Disk Info</h2>’ Out-String

$head @’


body { background-color:#dddddd;


font-size:12pt; }

td, th { border:1px solid black;

border-collapse:collapse; }

th { color:white;

background-color:black; }

table, tr, td, th { padding: 2px; margin: 0px }

table { margin-left:50px; }



ConvertTo-HTML -head $head -PostContent $frag1,$frag2 -PreContent “<h1>Hardware Inventory for SERVER2</h1>”

# Output Screenshot


Posted in Mix & Match, Powershell | Tagged: | 7 Comments »

%d bloggers like this: