Product: PowerShell Universal
Version: 3.7.10
Just sharing this because I’m happy I figured it out.
I have a table that is populated with machine names in the first column. The second column I wanted an icon to show if the machine was currently up, and the third a button to refresh the second column, but only for that row.
New-UDDynamic -id "dyn_Computers" -Content {
if ($session:computers){
$columns = @(
New-UDTableColumn -property Name -Title "Name" -DefaultSortColumn
New-UDTableColumn -property online -Title "Online" -Render {
New-UDDynamic -id "dyn_Up_$($eventdata.name)" -Content {
If (Test-Connection $eventdata.name -Count 1 -Quiet){
New-UDIcon -Icon sith -Style @{
backgroundColor = "green"
}
}
else {
New-UDIcon -Icon sith -Style @{
backgroundColor = "red"
}
}
}
}
New-UDTableColumn -property refresh -Title "Refresh Row" -Render {
New-UDButton -Text "Refresh Row" -OnClick {
sync-udelement -id "dyn_Up_$($eventdata.name)"
}
}
)
New-UDTable -Data $session:computers -Columns $columns -showselection
}
} -LoadingComponent {
new-udprogress -Circular
}
I found that I needed to make the UDDynamic name unique to each row, so I had the dynamic ID include $eventdata.name, and then had the button refresh that UDDynamic with the specific name.
Thinking on it more I may have it only check to see if the machine is up on selection. As it is this could cause a lot of traffic if there are a lot of results.
Any suggestions on a better way to do it?