Created
November 29, 2022 09:27
-
-
Save adamdriscoll/0f59d2becdec536db2992571c710f9a1 to your computer and use it in GitHub Desktop.
People Picker for PowerShell Universal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-User { | |
1..100 | ForEach-Object { | |
[PSCustomObject]@{ | |
UserName = "User$_" | |
First = "Bill" | |
Last = $_ | |
Avatar = (Get-ChildItem "$Repository\Avatars" | Get-Random).Name | |
} | |
} | |
} | |
New-UDDashboard -Title 'PowerShell Universal' -Content { | |
$Session:Users = [System.Collections.Generic.List[object]]::new() | |
New-UDAutocomplete -OnLoadOptions { | |
Get-User | Where-Object { $_.UserName -like "*$UserName*" } | Select-Object -First 5 -ExpandProperty 'UserName' | ConvertTo-Json | |
} -OnChange { | |
$Session:Users.Add((Get-User | Where-Object { $_.UserName -eq $EventData })) | Out-Null | |
Sync-UDElement -Id 'users' | |
} | |
New-UDDynamic -Id 'users' -Content { | |
New-UDList -Children { | |
$Session:Users | ForEach-Object { | |
New-UDListItem -Label $_.UserName -SubTitle "$($_.First) $($_.Last)" -AvatarType 'Avatar' -SecondaryAction { | |
$UserName = $_.UserName | |
New-UDIconButton -Icon (New-UDIcon -Icon 'Trash') -OnClick { | |
$RemoveUser = $Session:Users | Where-Object { $_.UserName -eq $UserName } | |
$Session:Users.Remove($RemoveUser) | |
Sync-UDElement -Id 'users' | |
} | |
} -Source "/avatars/$($_.Avatar)" | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
New-PSUPublishedFolder -RequestPath "/avatars" -Path "C:\ProgramData\UniversalAutomation\Repository\avatars" -DefaultDocument @() | |
# Random Avatar Generator: http://vuejs-avataaars.surge.sh/?ref=morioh.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment