Enhanced-Html Header coloum sorting

Welcome Forums General PowerShell Q&A Enhanced-Html Header coloum sorting

This topic contains 3 replies, has 3 voices, and was last updated by

2 years, 2 months ago.

  • Author
  • #11744

    Topics: 1
    Replies: 0
    Points: 0
    Rank: Member


    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 {


    BEGIN {
    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

  • #11752

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

  • #63943

    Topics: 1
    Replies: 5
    Points: 21
    Rank: Member

    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?

    • #63977

      Topics: 1
      Replies: 5
      Points: 21
      Rank: Member

      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"

The topic ‘Enhanced-Html Header coloum sorting’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort