Enhanced-Html Header coloum sorting

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Tony Bulding Tony Bulding 2 months, 2 weeks ago.

  • Author
    Posts
  • #11744
    Profile photo of Kunal Udapi
    Kunal Udapi
    Participant

    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 = @"

    "@

    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'='

    ♦ Virtual machines

    ';
    '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'="

    VMInventory

    ";
    '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

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

    System Report for $computer";
    'HTMLFragments'=@($html_pr)}
    ConvertTo-EnhancedHTML @params |
    Out-File -FilePath $filepath
    #>
    }

    }
    Get-VMInventory -path c:\temp

  • #11752
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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
    Profile photo of Tony Bulding
    Tony Bulding
    Participant

    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
      Profile photo of Tony Bulding
      Tony Bulding
      Participant

      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"

You must be logged in to reply to this topic.