0
votes

I try to convert a PSObject to a HTML table and get System.Object[] as output.

$Result = New-Object PSObject

foreach ($Location in $Locations) {
    $Servers = GetServers -Location $Location
    $Value = @()

    foreach ($Server in $Servers) {
        if (Test-Path Path) {
            $value += $Server #Background of td should be green
        } else {
            $Value += $Server #Background of td should be red
        }
    }

    $Result | Add-Member -Type NoteProperty -Name $Location -Value $Value
}

$Result ConvertTo-Html

Without converting to HTML the output is:

Location1  : {Server1, Server2}
Location2  : {Server3, Server4}
Location3  : {Server5, Server6}

Trying to convert:

<td>System.Object[]</td>

And I'd like to have a table like:

Location1     Location2     Location3
---------     ---------     ---------                                                                 
Server1       Server3       Server5
Server2       Server4       Server6

If it's possible I would like to have different <td> background (as commented in the script).

1
-Value ($Value -join ', ')Mathias R. Jessen

1 Answers

0
votes

ConvertTo-Html doesn't know how to format string arrays, so you'll have to convert the value to a string before passing it to the cmdlet:

$Result | Add-Member -Type NoteProperty -Name $Location -Value ($Value -join ', ')