Product: PowerShell Universal
Version: 1.5.15
I’m trying to generate a table with some custom formatting based on the value of a cell but I cannot get it to render at all. I just get a blank page. Any idea how I can troubleshoot this?
Here’s the table code:
$Pages += New-UDPage -Name 'StatusTest' -Content {
#Dynamic element to update only the table and not the whole page
New-UDDynamic -Id 'StatusTableTest' -Content {
#Retrieve content for table
$Data = foreach ($File in (Get-ChildItem -Path C:\PSU\EnrolledStations -Filter *.json)) {
Get-content $File.fullname | ConvertFrom-Json | Select-Object Station, StoredCustomer, LastSeen, Build
}
#Resort table by the station number (converts str stattion to int)
$Data = $Data | Sort-Object -Property {
if (($i = $_.Station -as [int])) { $i } else { $_ }
} -Descending
#Create table
New-UDTable -Title "Stations Status" -Headers @('Station','LastSeen') -Endpoint {
$Data | ForEach-Object {
$BgColor = 'green'
$FontColor = 'white'
if ((New-TimeSpan -Start $_.LastSeen -End (Get-Date).Minute) -gt 2 ){
$BgColor = 'red'
$FontColor = 'white'
}
[PSCustomObject]@{
Station = $_.Station
LastSeen = New-UDElement -Tag 'div' -Attributes @{ style = @{ 'backgroundColor' = $BgColor; color = $fontColor } } -Content { $_.LastSeen }
}
} | Out-UDTableData -Property @('Station','LastSeen')
}
}
}
Here’s the value of $Data:
[
{
"Station": "1",
"Build": null,
"Source": null,
"Transaction": "7feedfc8",
"IP": "10.69.9.1",
"LastSeen": "7/8/2021 5:00:04 PM",
"StoredCustomer": null
},
{
"Station": "2",
"Build": null,
"Source": null,
"Transaction": "45be9e9d",
"IP": "10.69.9.2",
"LastSeen": "7/8/2021 4:59:24 PM",
"StoredCustomer": null
},
{
"Station": "3",
"Build": null,
"Source": null,
"Transaction": "5c2446d1",
"IP": "10.69.9.3",
"LastSeen": "7/8/2021 4:58:34 PM",
"StoredCustomer": null
}
]