Dynamically create UDColumns

Hi,

thats because you cannot match $EventData with a string like “PASS” because $EventData is a PSCustomObject of the concurrent Row so you need to identify the indentifier before.
Something like this should work for you:

$columns = @(
    New-UDTableColumn -Property "Server" -Title "Server"
    (1..10 | ForEach-Object {
            $check_n = "Check$_"
            New-UDTableColumn -Property "$check_n" -Title "$check_n" -OnRender {
                $CheckProperty = $EventData.PSObject.Properties.Name | Where-Object { $_ -match "Check" }
                if ($EventData.$CheckProperty -eq "PASS") {
                    New-UDIcon -Icon check -Color green -Size sm
                } elseif ($EventData.$CheckProperty -eq "FAIL") {
                    New-UDIcon -Icon times -Color red -Size sm
                } else {
                    New-UDTypography "N/A"
                }
            }
        }
    )
)

Edit:
The example above only works with one column named “CheckXXX”.
Here is a example of a working set of Servers with 10 checks, also you need to use -LoadRows in New-UDTable to get $EventData.$Property to work

$columns = @(
    New-UDTableColumn -Property "Server" -Title "Server"
    (1..10 | ForEach-Object {
            $check_n = "Check$_"
            $OnRender = {
                $CheckProperty = $EventData.$Property
                if ($CheckProperty -eq "PASS") {
                    New-UDIcon -Icon check -Color green -Size sm
                } elseif ($CheckProperty -eq "FAIL") {
                    New-UDIcon -Icon times -Color red -Size sm
                } else {
                    New-UDTypography "N/A"
                }
            }
            New-UDTableColumn -Property "$check_n" -Title "$check_n" -OnRender $OnRender
        }
    )
)

$TableData = 1..10 | Foreach-Object {
    $InnerData = [PSCustomObject]@{
        Server = "Server_$_"
    }

    1..10 | Foreach-Object {
        $CheckKey = "Check$_"
        $RandomValue = Get-Random -Minimum 1 -Maximum 10
        $CheckValue = if($RandomValue % 2 -eq 0) {
            "PASS"
        } elseif ($RandomValue % 3 -eq 0) {
            "FAIL"
        } else {
            "N/A"
        }
        Add-Member -InputObject $InnerData -NotePropertyName $CheckKey -NotePropertyValue $CheckValue
    }

    $InnerData
}

New-UDTable -Columns $columns -LoadRows {
    $TotalCount = $TableData.Count
    $TableData | Out-UDTableData -Page $EventData.Page -TotalCount $TotalCount -Properties $EventData.Properties
}