Hello All,
I am new to the forums, but need some help with the ‘ConvertTo-EnhancedHTML’ module. I am trying to create an HTML report which displays all of the current snapshots we have for our Hyper-V cluster. I have worked on it for several days and finally have the report looking as i want it with the exception of the -PostContent. When I add the ‘PostContent’ in my params and then splat that to the ‘ConvertTo-EnhancedHTMLFragment’ command it seems to put the PostContent at the top of the page. vs after the table. The PreContent seems to be fine. Below is the code i am using. The “$ProdClusterVMs” is just a collection of all VM’s in the cluster.
Function SnapShotReport { $snapOut1 = @() $snapOut2 = @() $clusterTotal = @() $clusterSnapTotal = @() foreach ($vm in $PRODclusterVMs) { $snapcount = (Get-VMSnapshot -VMName $vm.Name -ComputerName $vm.ComputerName).Count if ($snapcount -le 0) { Write-Host -ForegroundColor Gray "No SnapShots Found -"$vm.Name } else { $clusterSnapTotal += $snapcount $totalSize = @() $paths = @() $sizes = @() $snaps = Get-VMSnapshot -VMName $vm.Name -ComputerName $vm.ComputerName | select -ExpandProperty harddrives | % {Get-VHD $_.Path -ComputerName $vm.ComputerName} | Where-Object {$_.ParentPath -ne $null} $active = Get-VM -name $vm.Name -ComputerName $vm.ComputerName | select -ExpandProperty harddrives | % {Get-VHD $_.Path -ComputerName $vm.ComputerName} $allSnaps = $snaps + $active foreach ($snap in $allSnaps) { $snapsize = [math]::Round($snap.fileSize/1GB,2) $diskPath = $snap.path $totalSize += $snap.FileSize $paths += $diskPath $sizes += $snapsize } $p = $paths | ForEach-Object { [string]$_ +"<br>" } $s = $sizes | ForEach-Object { [string]$_ +"<br>" } #GET total Snapshot Size $sum = [Math]::Round((($totalSize | measure -Sum).Sum)/1GB,2) $clusterTotal += $sum #Build Hashtable of the properties for the table $props = @{ 'VM Name' = $vm.Name; 'Snapshot Count' = $snapcount; 'Total Size (GB)' = $sum } $props.add('Snapshot Path Detail',$p) $props.add('Snapshot Size Detail',$s) #Create PSObject and then add to the SnapOut Array $custObj2 = New-Object -TypeName PSObject -Property $props $snapOut2 += $custObj2 } } #Get total snapshot count and size $clustTotal = ($clusterTotal | measure -Sum).Sum $clustSnapTotal = ($clusterSnapTotal | measure -Sum).Sum #Begin HTML Output $pre = "
$($PROD) Cluster Snapshot Report
" $post = "There are a total of $($clustSnapTotal) snapshots with a total size of $($clustTotal)GB
" $params = @{'PreContent' = $pre; 'MakeTableDynamic' = $true; 'TableCssClass' = 'grid'; 'Properties' = 'VM Name', 'Snapshot Count', 'Total Size (GB)', 'Snapshot Size Detail', 'Snapshot Path Detail'; 'PostContent' = $post } $snapOut2 | ConvertTo-EnhancedHTMLFragment @params } $fragment = SnapShotReport ConvertTo-EnhancedHTML -HTMLFragments $fragment -CssUri "E:\Installs\Scripts\Hyper-V\styles2.css" | Out-File "C:\windows\temp\2Report.html"When looking at the HTML generated, the tag (ie… the PreContent) is being put outside the where the table is. However the the tag (ie… the PostContent) is being placed inside the which it seems like it should be outside of it at the end? Any thoughts or guidance on this would be much appreciated. Thanks so much in advance.
Andrew