Product: PowerShell Universal
Version: 3.9.4
Hey All,
I am trying to get started with using tables to view, add, or delete information. I am struggling with New-UDTable and the Dynamic commands. In both scenarios I tried review the forums and documentation to think of a way to accomplish it. Odds are I am missing something or overlooking an error in my code, or expecting something that the platform can’t do.
Scenario 1: Wanted to build an on call schedule. My POC was CSV based. Loaded the CSV and tried to populate the table. I had Sync-UDElement in my onclick block, but the table wouldn’t refresh unless I refreshed the screen. I tried a number of things like using the session variable, moving commands around, and even tried loading the CSV into a data table to see if that would make a difference. Here is the code I am currently working with.
New-UDGrid -Container -Content{
New-UDGrid -Item -MediumSize 3 -Content {}
New-UDGrid -Item -MediumSize 6 -Content {
$Session:Data = Get-Content c:\temp\OnCallRotation.csv -Raw | ConvertFrom-Csv
New-UDContainer -Content {
New-UDGrid -Item -SmallSize 5 -Content {
New-UDTextbox -Label "Email Address" -Id "newEmailAddress" -FullWidth
New-UDButton -Text "New Employee" -OnClick {
$addEmployee = (Get-UDElement -id "newEmailAddress").value
$addOnCallDate = (Get-UDElement -id "onCallStart").value | Get-Date -Format "MM/dd/yyyy"
Write-Output "`n$addEmployee,$addOnCallDate" | Out-File c:\Temp\OnCallRotation.csv -Append
Sync-UDElement -Id "tbl"
}
}
New-UDGrid -Item -MediumSize 1 -Content {}
New-UDGrid -Item -MediumSize 5 -Content {
New-UDDatePicker -Id "onCallStart" -Variant static
}
}
New-UDDynamic -AutoRefresh -id "tbl" -Content{
$Session:Data = Get-Content c:\temp\OnCallRotation.csv -Raw | ConvertFrom-Csv
New-UDTable -Data $Session:Data -Id "tblOnCallSchedule"
}
}
}
Scenario 2: Wanted to build a screen to allow specific users to adjust certain group memberships. A dropdown populated with AD groups (Working), then when they select a group, the table populates with the members of the groups. Didn’t get as far to determine the ability to add or remove users, but wanted to get the table first, as I know you can add buttons. Now, I am sure that an AD result doesn’t directly translate to a UDTable but I also tried the same steps as I listed above to get it to populate.
# Use Get-UDPage -Name 'Test Site' to use this page in your dashboard
New-UDGrid -Container -Content{
New-UDGrid -Item -MediumSize 3 -Content {}
New-UDGrid -Item -MediumSize 6 -Content {
New-UDCard -Title "Group Modifier" -TitleAlignment Center -Content{
$Groups = Get-ADGroup -Filter 'Name -like "Group*"' -SearchBase 'FicticiousDomainOU' | Select Name
New-UDTypography "Selecting the group from the list will allow you to modify its members." -Align center
New-UDSelect -Label "Groups" -FullWidth -Id "cmbGroupName" -Option {
foreach ($Group in $Groups){
New-UDSelectOption -Name $($Group.Name) -Value $($Group.Name)
}
} -OnChange {
Sync-UDElement -Id 'table'
}
$Members = Get-ADGroupMember -Identity $(Get-UDElement -Id cmbGroupName).Value | Get-ADUSer | Select Name
New-UDDynamic -Id 'table' {
New-UDTableColumn -Property Name -Title "Name"
New-UDTable -Data $Members
}
}
}
}
What am I missing?