Author Posts

November 30, 2013 at 12:24 pm


I am using enhancedHTML v2 to pull up all VMs records from vcenter. I am getting them correctly but when reports are generated column headers are sorted alphabetically, I used select-object in
variable $ but it is not working for me . Can you please guide me what I am missing in this script?

function Get-VMInventory {


Remove-Module EnhancedHTML2
Import-Module EnhancedHTML2
Remove-PSSnapin vmware.vimautomation.core
Add-PSSnapin vmware.vimautomation.core

$style = @"


function Get-RawData {
$procs = Get-VM $VMname
foreach ($proc in $procs) {
$props = @{'VMName'=$proc.Name;
'IP Address'= $proc.Guest.IPAddress[0];
'PowerState'= $proc.PowerState;
'Hardware Version'= $proc.Version;
'vCPUs'= $proc.NumCpu;
'Memory (GB)'= $proc.MemoryGB;
'HardDisk (GB)'= $proc.ProvisionedSpaceGB -as [int];
'Datastore'= (Get-Datastore -vm $vm) -split ", " -join "+"
'Operating System'= $proc.guest.OSFullName
'EsxiHost'= $proc.VMHost;
'Folder'= $proc.folder;
'HW Version'=$proc.version}
New-Object -TypeName PSObject -Property $props

function Get-ExtendedBase {
foreach ($computer in $(Get-VM).name) {
Get-RawData -VMname $computer

$filepath = Join-Path -Path $Path -ChildPath "Reports.html"

$params = @{'As'='Table';

♦ Virtual machines

$html_pr = Get-ExtendedBase | Select-Object -Property 'VMName', 'IP Address', 'PowerState', 'vCPUs', 'Memory (GB)', 'HardDisk (GB)', 'Datastore', 'Operating System', 'EsxiHost', 'Hardware Version', 'Folder' | ConvertTo-EnhancedHTMLFragment @params

$params = @{'CssStyleSheet'=$style;


ConvertTo-EnhancedHTML @params |
Out-File -FilePath $filepath

< # $params = @{'CssStyleSheet'=$style; 'Title'="System Report for $computer"; 'PreContent'="

System Report for $computer";
ConvertTo-EnhancedHTML @params |
Out-File -FilePath $filepath

Get-VMInventory -path c:\temp

December 1, 2013 at 9:23 am

So, the module just kind of takes what you give it. In other words, if the columns aren't coming out in the order you want, the EnhancedHTML2 module isn't doing anything about the re-ordering. Usually, what Select-Object outputs is ordered, meaning it should be maintained. If it isn't… dunno.

If you take the output of your Select-Object and just look at that, are the columns what you want?

EnhancedHTMLFragment does have its own -Properties parameter. You might try specifying your properties there, since that kind of forces the module to use them in that order.

February 10, 2017 at 4:02 pm

I see a similar issue, however, I can tell that the re-sorting is happening when the datatable is being initialized.
IE blocks the initial loading of the javascript, and until you allow the script to execute the sorting is correct.

Is there a way to pass parameters to the datatable initialization from within the module?

February 10, 2017 at 10:36 pm

the only way I was able to assert my will on this was to overwrite the returned code before writing it to disk.

$InitOld = 'dataTable()'
$InitNew = 'dataTable({"order": [[ 1, "desc" ]]})'
(ConvertTo-EnhancedHTML @paramblock).replace($InitOld, $InitNew) |Out-file -FilePath "$env:My_Outputs\MyReport.html"