Enhanced-Html Header coloum sorting

Hello,

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 $html.pr but it is not working for me . Can you please guide me what I am missing in this script?

function Get-VMInventory {

[CmdletBinding()]
param(

[Parameter(Mandatory=$True)]
[string]$Path

)
BEGIN {
Remove-Module EnhancedHTML2
Import-Module EnhancedHTML2
Remove-PSSnapin vmware.vimautomation.core
Add-PSSnapin vmware.vimautomation.core
Connect-Viserver 127.0.0.1
}
PROCESS {

$style = @"
<style>
body {
color:#333333;
font-family:Calibri,Tahoma;
font-size: 10pt;
}
h1 {
text-align:center;
}
h2 {
border-top:1px solid #666666;
}

th {
font-weight:bold;
color:#eeeeee;
background-color:#333333;
cursor:pointer;
}
.odd { background-color:#ffffff; }
.even { background-color:#dddddd; }
.paginate_enabled_next, .paginate_enabled_previous {
cursor:pointer;
border:1px solid #222222;
background-color:#dddddd;
padding:2px;
margin:4px;
border-radius:2px;
}
.paginate_disabled_previous, .paginate_disabled_next {
color:#666666;
cursor:pointer;
background-color:#dddddd;
padding:2px;
margin:4px;
border-radius:2px;
}
.dataTables_info { margin-bottom:4px; }
.sectionheader { cursor:pointer; }
.sectionheader:hover { color:red; }
.grid { width:100% }
.red {
color:red;
font-weight:bold;
}
</style>
"@

function Get-RawData {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)][string]$VMName
)
$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';
                'PreContent'='&lt;h2&gt;&diams; Virtual machines&lt;/h2&gt;';
                'EvenRowCssClass'='even';
                'OddRowCssClass'='odd';
                'MakeTableDynamic'=$true;
                'MakeHiddenSection'=$false;                    
                'TableCssClass'='grid'}
    $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;
                'Title'="VMInventory";
                'PreContent'="&lt;h1&gt;VMInventory&lt;/h1&gt;";
                'HTMLFragments'=@($html_pr);
                'jQueryDataTableUri'='http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.3/jquery.dataTables.min.js';
                'jQueryUri'='http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js'} 
    ConvertTo-EnhancedHTML @params |
    Out-File -FilePath $filepath

    &lt;#
    $params = @{'CssStyleSheet'=$style;
                'Title'="System Report for $computer";
                'PreContent'="&lt;h1&gt;System Report for $computer&lt;/h1&gt;";
                'HTMLFragments'=@($html_pr)}
    ConvertTo-EnhancedHTML @params |
    Out-File -FilePath $filepath
    #&gt;
}

}
Get-VMInventory -path c:\temp

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.

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?

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”