I just found out about Universal Dashboard yesterday, and I love it.
I may not be using it correctly, though. I have the following sample script:
Import-Module UniversalDashboard
Get-UDDashboard | Stop-UDDashboard
$services = Get-Content 'C:\temp\Services.txt'
$Dashboard = New-UDDashboard -Title "Service Groups" -Content {
New-UDLayout -Columns 3 -Content {
foreach ($service in $services) {
New-UDCard -Title "$($service) services" -Content {
$criteria = "$($service)*"
New-UDElement -Tag "div" -Content {"$((Get-Service | ? displayname -like "$($service)*").Count) members in group"}
New-UDButton -Text "Generate $($service) list" -OnClick {
Get-Service | ? displayname -like "$($service)*" |
Select Name, DisplayName, status |
Export-Csv -Path c:\temp\outServices.txt -NoTypeInformation
Show-UDToast -message "$($service) member list generated." -Position bottomRight -Duration 3000
}
}
}
}
}
Start-UDDashboard -Dashboard $Dashboard -Port 10001
My services.txt file contains the following 3 lines:
Application
Diagnostic
Hyper-V
Here is a screenshot:
When I click on the UDButton, I would like to export the services beginning with the name on the card, and display a toast message. For some reason, $service is being ignored in both the button’s OnClick event and in the toast message.
Any assistance would be appreciated. Thanks!