PSWriteHTML icon indicating copy to clipboard operation
PSWriteHTML copied to clipboard

Transpose Parameter for Out-HtmlView?

Open rk-h opened this issue 3 years ago • 6 comments

When sending data (aka a PS Object) to Out-HtmlView I want to transpose rows into columns. Is this possible with the current module's version?

E. g.: Form Exchange Shell I saved the result from 'Get-SendConnector' to XML. Now I import that file into $Q: '$q1=Import-Clixml -LiteralPath .\SendConnector.xml'

The result looks like this image.

The attributes of the two connectors are in rows below each other and the table has many columns next to each other. But I would have liked to swap: the connectors (in the example here there are two) next to each other in columns and the attributes below each other.

As a workaround, I open the table as an Excel file, copy the rows and paste them in a new sheet using the transpose function. This then looks like this: image

I need this quite often. It would be nice if this function was available directly in the module.

rk-h avatar Apr 10 '22 19:04 rk-h

Out-HtmlView -Transpose is it not working?

PrzemyslawKlys avatar Apr 10 '22 19:04 PrzemyslawKlys

Oh - my bad. I overlooked this parameter. Sorry! But when I use Out-HtmlView with -Transpose I can only see the first connector and the second one is not shown. image

When I use -FlattenObject too the result is quite weird or mixed. image

rk-h avatar Apr 10 '22 20:04 rk-h

I guess my implementation of it is incorrect or was approached for showing a single object transposed. To transpose correctly more than 1 object you would need to provide a way to define column names (object names). You have picked X and Y yourself.

PrzemyslawKlys avatar Apr 10 '22 20:04 PrzemyslawKlys

Maybe this helps. I just noticed that the second object is included in the output after all. But not in another column as expected. The second object is below the first one and all row labels are repeated. Here is an example for Get-ExchangeCertificate: image

rk-h avatar Apr 10 '22 20:04 rk-h

I guess my implementation of it is incorrect or was approached for showing a single object transposed. To transpose correctly more than 1 object you would need to provide a way to define column names (object names). You have picked X and Y yourself.

Not quite. X and Y are the anonymized names of the connectors. I copied this information manually to the top to improve readability for me. In the original output the first line contains the name of the first attribute of the object. DNSRoutingEnabled' in the case.

Regardless - thanks for the great module. It helps me in other places as well!

rk-h avatar Apr 10 '22 20:04 rk-h

Right, in your case it's DNSRoutingEnabled, but for others, it may be a value from DisplayName, and for others value from FriendlyName. It's just something user dependant which means there needs to be a choice and the value needs to be unique. It can't assume things.

PrzemyslawKlys avatar Apr 10 '22 20:04 PrzemyslawKlys

New versions resolve this issue:

1.21.0 - 2024.06.29

  • Changed behavior of Transpose in New-HTMLTable / Out-HtmlView
  • Added TransposeLegacy to New-HTMLTable / Out-HtmlView to keep old behavior
  • Added TransposeName to New-HTMLTable / Out-HtmlView to allow for custom name (default is Object 0, Object 1, Object 2)
  • Added TransposeProperty to New-HTMLTable / Out-HtmlView to allow for transposing on unique value from specific property (ex. ServerName)
  • Added Out-HtmlView additional options PrettifyObject, PrettifyObjectSeparator, PrettifyObjectDateTimeFormat

Those changes resolve: #316

$Object = @(
    [PSCustomObject] @{
        Test  = 5
        Ello  = 'Motto'
        Hello = 'Totto'
    }
    [PSCustomObject] @{
        Test  = 5
        Ello  = 'Motto'
        Hello = 'Totto'
    }
    [PSCustomObject] @{
        Test  = 5
        Ello  = 'Motto'
        Hello = 'Totto'
    }
    [PSCustomObject] @{
        Test  = 5
        Ello  = 'Motto'
        Hello = 'Totto'
    }
    [PSCustomObject] @{
        Test  = 5
        Ello  = 'Motto'
        Hello = 'Totto'
    }
    [PSCustomObject] @{
        Test  = 3
        Ello  = 'Lotto'
        Hello = 'Totto'
    }
)


$Object | Out-HtmlView -Transpose -TransposeName 'Test ' -Filtering

New-HTML -TitleText $Title -Online -FilePath $PSScriptRoot\Example-TableTranspose01.html {
    New-HTMLTable -DataTable $Object -Filtering -Transpose
} -ShowHTML

PrzemyslawKlys avatar Jun 29 '24 18:06 PrzemyslawKlys