Hyper-V: Get VM Name, IP Address, VM Status output to HTML Report

# Variables
$DateStamp = get-date -uformat "%m-%d-%Y"
$file = "C:\Project6\CompletedScript\Report_$DATEStamp.txt"
$VMS = get-vm
$computers = $Env:COMPUTERNAME

Write-Host "Collecting Data on the Servers" -ForegroundColor "Yellow"

# put todays date and time in the file
echo "Health Report was ran on" | out-file $file
get-date | out-file $file -append

# get the vhost uptime
Get-CimInstance Win32_OperatingSystem -comp $computers | Select @{Name="VHostName";Expression={$_."csname"}},@{Name="Uptime = D:H:M:S.Millseconds";Expression={(Get-Date) - $_.LastBootUpTime}},LastBootUpTime | format-table -autosize | out-file $file -append

# get the vhost name, total virtual CPU count, total RAM, virtualharddiskpath and virtualmachinepath
Get-VMHost | Select @{Name="VHostName";Expression={$_."Name"}},@{N="Total RAM(GB)";E={""+ [math]::round($_.Memorycapacity/1GB)}},logicalprocessorcount,virtualharddiskpath,virtualmachinepath | format-table -autosize | out-file $file -append

echo "VHOST Server IP Addresses and NIC's" | out-file $file -append
Get-WMIObject win32_NetworkAdapterConfiguration | Where-Object { $_.IPEnabled -eq $true } | Select IPAddress,Description | format-table -autosize | out-file $file -append

echo "VHOST Server drive C: Disk Space" | out-file $file -append
# to get D: drive add ,D after C - E: drive ,E etc.
Get-psdrive C | Select Root,@{N="Total(GB)";E={""+ [math]::round(($_.free+$_.used)/1GB)}},@{N="Used(GB)";E={""+ [math]::round($_.used/1GB)}},@{N="Free(GB)";E={""+ [math]::round($_.free/1GB)}} |format-table -autosize | out-file $file -append

echo "VHosts virtual switch(s) information" | out-file $file -append
get-vmswitch * | out-file $file -append

echo "Total number of VM's on server" | out-file $file -append
echo "------------------------------" | out-file $file -append
$VMS.Count | out-file $file -append
echo " " | out-file $file -append

echo "NOTE: Nothing listed under DVD Media Path = Nothing mounted in DVD" | out-file $file -append
$outputArray = @()
foreach($VM in $VMS)
$VMsRAM = [math]::round($VM.Memoryassigned/1GB)
$VMsCPU = $VM.processorCount
$VMsState = $VM.State
$VMsStatus = $VM.Status
$VMsUptime = $VM.Uptime
$VMsAutomaticstartaction = $VM.Automaticstartaction
$VMsIntegrationServicesVersion = $VM.IntegrationServicesVersion
$VMsReplicationState = $VM.ReplicationState
$VHDs = Get-VHD -VMId $VM.VMiD
$VHDsGB = [math]::round($VHDs.FileSize/1GB)
$VMDVD = Get-vmdvddrive -VMname $VM.VMname

$output = new-object psobject
$output | add-member noteproperty "VM Name" $VM.Name
$output | add-member noteproperty "RAM(GB)" $VMsRAM
$output | add-member noteproperty "vCPU" $VMsCPU
$output | add-member noteproperty "State" $VMsState
$output | add-member noteproperty "Status" $VMsStatus
$output | add-member noteproperty "Uptime" $VMsUptime
$output | add-member noteproperty "Start Action" $VMsAutomaticstartaction
$output | add-member noteproperty "Integration Tools" $VMsIntegrationServicesVersion
$output | add-member noteproperty "Replication State" $VMsReplicationState
$output | add-member noteproperty "VHD Path" $VHDs.Path
$output | add-member noteproperty "Size GB" $VHDsGB
$output | add-member noteproperty "VHD Type" $VHDs.vhdtype
$output | add-member noteproperty "VHD Format" $VHDs.vhdformat
$output | add-member noteproperty "DVD Media Type" $VMDVD.dvdmediatype
$output | add-member noteproperty "DVD Media Path" $VMDVD.path
$outputArray += $output
write-output $outputarray | sort "VM Name" | format-table * -autosize | out-string -width 600 | out-file $file -append

Echo "VM's BIOS setting" | out-file $file -append
get-vmbios * | sort "VMName" | Format-Table -autosize | out-file $file -append

echo "VM's Virtual Switch name and IP address" | out-file $file -append
get-vmnetworkadapter * | Select vmname,switchname,ipaddresses | sort "VMName" | format-table -autosize | out-file $file -append

echo "VM's Snapshot and location" | out-file $file -append
echo "If nothing is Listed below, then there are no Snapshots" | sort "VMName" | format-table -autosize | out-file $file -append
get-vmsnapshot -vmname * | out-file $file -append

#load the report in notepad
notepad.exe "C:\Project6\CompletedScript\Report_$DATEStamp.txt"
<article class="topic-body">

I have this script here that gets info off the vms I have running and the local host server but right now it just outputs to a text file. Can anyone point me in the right direction as to how I would start having this output to a nicer html file.


Hey AlexMac14,

First up, I suspect your “code” tags would work better as “pre” tags.

Secondly, the quickest way to do so would be to use ConvertTo-HTML, which takes an InputObject (from the pipeline if you want) and converts it into a HTML table. You can prefix appropriate CSS / styling, and use -Fragment to create multiple sections and generate a full report before outputting it to a file for distribution.

A quick example is below

$Process = Get-Process | Select-Object -First 4 -Property Name,ID,handles | ConvertTo-Html -Fragment
$Service = Get-Service | Select-Object -First 4 -Property Name,Status,DisplayName | ConvertTo-Html -Fragment
ConvertTo-Html -Body ($Process+$Service) -Head "List of process and services"  > C:\Temp\test.html
Start-Process C:\Temp\test.html

When you use -Fragment, it creates only the html table section, then you finally add these two tables to one single html file. you can do many more for html using PowerShell.

There is also a free eBook over here under Free Resources > eBook > Creating HTML Reports in Powershell