I have a simple dashboard that takes a User ID via a New-UDInputAction, creates a variable $UserID, then fetches a list of AD groups that ID is a member of and displays them in a New-UDTable. That part works fine however, I want to be able to retain the value of $UserID to use in another section of the dashboard and have been unable to do so.
If I use a Scope, it either fails to work at all (pretty sure that’s my fault as I`m not 100% sure where in the code that should be defined) or retains it indefinitely so it is not overwritten with a new value if a new User ID is queried.
Code is below and yeah, it’s not pretty but it works up to a point (like me I guess )
I have Toasts set to trigger as progress indicators and the “EMail” button -OnClick should trigger a toast that also contains the $UserID variable.
Is what I`m attempting to do possible ?
Cheers,
Import-Module UniversalDashboard
Import-Module ActiveDirectory
Import-Module UniversalDashboard.Style
Get-UDDashboard | Stop-UDDashboard
$Dashboard = New-UDDashboard -Title "Orange Styled Page with Input and 4 buttons - Scratch copy" -NavBarcolor '#E98300' -Content {
$TopLevelServer= "DC.Contoso.com"
$ResourceDomainServer= "DC.Contoso.com"
$ResourceContextServer = "gb.Contoso.com"
New-UDRow -Columns {
New-UDColumn -Size 5 -Content {
New-UDStyle -Style '
.ud-input .btn {
background-color:#E98300;
}
' -Content {
New-UDInput -Title "Active Directory Group Membership" -Endpoint {
Param(
[Parameter(Mandatory)]
[string]$UserID)
New-UDInputAction -Content {
New-UDTable -Title "Active Directory Group Membership for $UserID " -Headers @("Active Directory Group Name") -Endpoint {
Show-UDToast -Title "Testing $UserID Variable" -Message "Fetching AD Group details for $UserID - Please Wait" -Theme dark -Duration 10000 -Balloon -Position center
Get-ADPrincipalGroupMembership -Identity $UserID -Server $TopLevelServer | Select-Object SamAccountName | Sort-Object SamAccountName | Out-UDTableData -Property @("SamAccountName")
Show-UDToast -Title "Testing $UserID Variable" -Message "Still going...." -Theme dark -Duration 10000 -Balloon -Position center
Get-ADPrincipalGroupMembership -Identity $UserID -Server $TopLevelServer -ResourceContextServer $ResourceContextServer | Select-Object SamAccountName | Sort-Object SamAccountName | Out-UDTableData -Property @("SamAccountName")
}
}
}
}
}
New-UDColumn -Size 3 -Content{
New-UDButton -Id 'Orange Email Button' -BackgroundColor "#E98300" -Text "1. EMail" -Style @{"margin-top"="8px";"Width"="100%";"Height"="50px"} -OnClick {
Show-UDToast -Title "Testing Email Button $UserID Variable" -Message "$UserID" -Theme dark -Duration 10000 -Balloon -Position center
}
New-UDButton -Id 'Button 2' -BackgroundColor "#FF0000" -Text "2." -Style @{"margin-top"="8px";"Width"="100%";"Height"="50px"} # -OnClick {
New-UDButton -Id 'Button 3' -BackgroundColor "#000000" -Text "3." -Style @{"margin-top"="8px";"Width"="100%";"Height"="50px"} # -OnClick {
New-UDButton -Id 'Button 4' -BackgroundColor "#006600" -Text "4." -Style @{"margin-top"="8px";"Width"="100%";"Height"="50px"} # -OnClick {
}
}
}
Start-UDDashboard -Dashboard $Dashboard -Port 10001 # -AutoReload