I’m attempting to create a table of Windows services and their states (Running or stopped) with a custom button on each row using the -Render parameter of New-UDTableColumn. The button will say either Start
or Stop
based on the state of the service and clicking a button will either start or stop the associated service.
I’m getting the error Cannot bind argument to parameter 'InputObject' because it is null.
and I’ve determined that it’s because the $Body variable is null.
I referenced the following resources when putting my code together:
- PowerShell Universal documentation
- New-UDTableColumn cmdlet documentation
Note: The cmdlet help for New-UDTableColumn states the following for the Render parameter:
How to render this table. Use this parameter instead of property to render custom content within a column. The $Body variable will contain the current row being rendered.
– I tried removing the Property parameter, but I get an error stating that it is required. - Forum post New-UDTable Column render
Below is the code I’m using. Is there anything in particular I’m doing wrong?
$srvrHostname = "Server1"
$WinServices = Get-WmiObject -ComputerName $srvrHostname -Class "win32_service" | Select-Object -First 10
$Theme = @{
light = @{
palette = @{
primary = @{
main = '#9e9e9e'
}
}
}
}
New-UDDashboard -Title "$srvrHostname Windows Services Status - TestEnv" -Theme $Theme -DefaultTheme 'Light' -Content {
$Header = New-UDCardHeader -Title "$srvrHostname Windows Services Status"
$Body = New-UDCardBody -Content {
$Data = $WinServices
$Columns = @(
New-UDTableColumn -Property Name -Title "Name"
New-UDTableColumn -Property State -Title "State"
New-UDTableColumn -Property Started -Title "Start/Stop" -Render {
$Item = $Body | ConvertFrom-Json
if ($Item.Started -eq $true) {
New-UDButton -Id "bloopers" -Text "Stop" -OnClick {
Show-UDToast -Message 'Starting Service...' -Duration 5000
}
} else {
New-UDButton -Variant text -Text 'Start' -OnClick {
Show-UDToast -Message 'Starting Service...' -Duration 5000
}
}
}
)
New-UDTable -Data $Data -Columns $Columns -Dense
}
New-UDCard -Body $Body -Header $Header
}
Product: PowerShell Universal
Version: 2.12.5