Hey everyone,
I’m relatively new coming into UD, and I’m starting with UD V3. I have found several examples on using colored text in a UD V2 Table, but I can’t seem to get this to work in UD V3. Is it possible, yet? If so, can someone point me to a working example, or take a shot at troubleshooting my code?
I uninstalled the previous version and deleted C:\ProgramData\PowerShellUniversal, prior to installing the latest version 1.4.6. I’m running this on Server 2019, and installed using the WMI file.
I’m starting with something simple, like below, and once I can get the colored text working I’ll expand with other DC tests and plug them into a DC Health table.
Using the below code, the table says [object Object] as the values of the “Online Status” column. If I change the if/else to simple string values of “True” or “False”, they are properly displayed in the table. How can I get colored text for these column values in the table?
When running the code in VS Code, line by line, everything works without error until the final line of New-UDDashboard.
The shell gives the error:
MethodException: C:\ProgramData\PowerShellUniversal\Dashboard\Frameworks\UniversalDashboard\3.1.4\UniversalDashboard.MaterialUI.psm1:2387:5
Line |
2387 | $Content.Register($Id, $Role, $PSCmdlet)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot find an overload for “Register” and the argument count: “3”.
When I browse to the dashboard and look at the log, I see the error:
PS: One or more errors occurred. (Cannot overwrite variable null because it is read-only or constant.) (Cannot overwrite variable null because it is read-only or constant.)
Thanks in advance!
$DCs = Get-ADDomainController -Filter * | Select-Object -first 5
$DCsHealth = @()
foreach ($DC in $DCs)
{
$pingTest = Test-Connection -Quiet -Count 1 $DC.HostName
if ($pingTest) {$online = New-UDElement -Tag 'div' -Attributes @{style = @{'backgroundColor' = 'green'; 'color' = 'white'}} -Content {"True"}}
else {$online = New-UDElement -Tag 'div' -Attributes @{style = @{ 'backgroundColor' = 'red'; 'color' = 'white'}} -Content {"False"}}
$DCsHealth += [PSCustomObject][Ordered]@{
'Name' = $DC.HostName
'IP' = $DC.IPv4Address
'Online' = $online
}# $DCsHealth
}# foreach ($DC in $DCs)
$columns = @(
New-UDTableColumn -Property Name -Title "DC Name"
New-UDTableColumn -Property IP -Title "IP Address"
New-UDTableColumn -Property Online -Title "Online Status"
)# columns
$table_DCsHealth = New-UDTable -Id 'customColumnsTable' -Data $DCsHealth -Columns $columns -Title "Domain Controllers Online Status"
$grid = New-UDGrid -Container -Content {
New-UDGrid -Item -LargeSize 6 -Content {$table_DCsHealth}
}# $grid
New-UDDashboard -Title "Component Test" -Content {$grid}