Hash Table Problem for EnhancedHtml2

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 2 months, 3 weeks ago.

  • Author
    Posts
  • #83512

    Des Davies
    Participant

    Hi All,

    I'm updating a report to include some formatting based on the information in a field. The report is built using the EnhancedHtml2 module. Everything works great in the report until I start to replace items in the 'properties' with a hash table. However, it is very hit and miss. Some of the hash tables work, then one in a set will throw errors. The two pieces of code below show one that works (Firewall Info), and another that throws on error (Software Info).

    Final note, even though an error is thrown, the code works as planned.

    Any thoughts would be much appreciated.
    Des

    The error thrown is:
    ConvertTo-EnhancedHTMLFragment : Hashtable missing Name and/or Expression key
    At C:\Program Files\WindowsPowerShell\Modules\UWMTools\fn-Srv-Get-ServerBuildReview.ps1:178 char:46
    + ... tml_Software = $SoftwareInfo | ConvertTo-EnhancedHTMLFragment @params
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,ConvertTo-EnhancedHTMLFragment

            # Get the Firewall Info
                $params = @{'As'='Table';
                    'PreContent'='FIREWALL';
                    'EvenRowCssClass'='even';
                    'OddRowCssClass'='odd';
                    'TableCssClass'='grid';
                    'Properties'=@{n='Firewall Zone';e={$_.FirewallZone}},
                                 @{n='Firewall State';e={$_.FirewallState};css={if ($_.FirewallState -ne 'Disabled') { 'red' }}}
                } #Params for Info
                $html_firewall = $FirewallInfo | ConvertTo-EnhancedHTMLFragment @params
                $html_output.Add($html_firewall) | Out-Null
    
            # Get the Install Software Info
                $params = @{'As'='Table';
                    'PreContent'='INSTALLED SOFTWARE';
                    'EvenRowCssClass'='even';
                    'OddRowCssClass'='odd';
                    'TableCssClass'='grid';
                    'Properties'='Publisher',
                                 @{n='Software';e={$_.Software};css={If ($_.Software -like 'VMWare Tools') { 'green' }}},
                                 'Version',
                                 'InstallDate'
                } #Params for Software Info
                $html_Software = $SoftwareInfo | ConvertTo-EnhancedHTMLFragment @params
                $html_output.Add($html_software) | Out-Null
    
  • #85333

    Don Jones
    Keymaster

    It could be a bug in the code (sorry, I'm just seeing this after being away for a while). But I'm not sure I've ever fed parameters the way you have. Try building a hash table just for the Properties parameter, and then feeding that to it in your splatted hash table, rather than trying to construct it all in one go. I'm wondering if some data structure isn't getting lost somehow. But aside from that, I'd have to add a breakpoint to the Fragment command in the module and debug it to see what's actually being fed to it in PSBoundParameters.

You must be logged in to reply to this topic.