Product: PowerShell Universal
Version: 5.4.3
Hey there, I dont know what I am doing wrong. I feel like this is a bug.
I first started with a simple transferlist filled dynamicly from an AutoComplete Component. At some point it just didnt add more than one Item to the TransferList. The hashtable of which I am generating the transferlist adds these entries when I check and output the hashtable data via $Session:Hashtable | Export-Clixml -Path "C:\temp\hashtable.xml"
I created a new Page, step by step building up the transferlist and didnt come across this “bug” again. Now when I changed my code from a simple New-UDCard -Title "Title"
to New-UDCard -Header $Session:CardHeader
etc… this bug showed up again, and I am not sure why this happens.
I also switched the New-UDDynamic to different places inside the $Session:CardHeader-Block but nothing seems to work.
The code below shows the whole App.
I appreciate any help or tips.
New-UDApp -Content {
[array]$ItemsRange = Get-PSUCache -Key 'AllSwGroupsIndex' # ItemsRange: collection of groups preloaded from database into the PSU Cache
$Session:Hashtable = [ordered]@{} # Hashtable: will be filled with groups selected from AutoComplet-Component
$Session:GroupsToAdd = @() # GroupsToAdd: will be filled based on selection in TransferList-Component
$Session:Index = 0 # Index: Value-Pair in $Hashtable
$Session:GroupsToAddIndex = 0 # GroupsToAddIndex: Value-Pair in $GroupsToAdd
[string]$Session:databaseContextPCs = "database:" # databaseContext*: Important to determine the current PSDrive for Cmd-Lets retrievieung Objects from Database (not used)
[string]$Session:databaseContextGroups = "database:\root" # databaseContext*: Important to determine the current PSDrive for Cmd-Lets retrievieung Objects from Database (not used)
## String-Filter Baukasten
$Session:RegexNameConvention = '(?m)^PC\d{5}' # RegexNameConvention: Regex pattern to search for PC Name like PC12345 for example
$Session:ReplaceJunk = ",|;|,|\.|\ |`t" # ReplaceJunk: Filters every not wanted Character in input String in UDTextfield
$Session:Head = '(|' # Head: head of LDAP-Filter to search for multiple objects in one request
$Session:End = ')' # End: added at the end of the LDAP-Filter
$Session:LDAPCall = '(Name:IgnoreCase=' # LDAPCall: Search for PC-Names, ignores upper or lower case
# Copy button to place it at the same level as subheader in UDCardHeader
$Session:Style = '
button[id="btn-compute-input"] {
margin-top: 41px;
}
'
# Creating UDCardHeader for User text input
$Session:CardHeader = New-UDCardHeader -Title "Computer-List" -SubHeader "copy filter" -Action (
New-UDIconButton -Id "btn-compute-input" -Disabled -Icon (New-UDIcon -Icon "copy" -Size sm) -OnClick {
Set-UDClipboard -Data $Session:FilterComplete -ToastOnSuccess -ToastOnError
Show-UDToast -Message "Filter copied" -Title "Filter" -Duration 5000 -Position 'topCenter'
}
)
# Creating UDCardBody for User text input
$Session:CardBody = New-UDCardBody -Content {
New-UDTextbox -Id 'asset-list' -Label 'Assetnamen' -Placeholder 'Liste von Rechnern' -Multiline -Rows 10 -RowsMax 200 -FullWidth -OnChange {
# Gets the value of textfield (Computerlist), could also just use $EventData
$Session:AssetList = (Get-UDElement -Id "asset-list").Value
$Session:Matches = @()
# Transforming EventData of Textfield into an Array with -split and delete junk like (,|;|,|\.|\ |`t)
$Session:AssetList = $Session:AssetList -split "\n" -replace $Session:ReplaceJunk
# Saving Computer which match NameConvention of company
$Session:Matches = $Session:AssetList -match $Session:RegexNameConvention
# If there are matches, count them for User feedback
# Build LDAP-Filter around found matches
if ($Matches -ne $False) {
Show-UDToast -Message "Es wurden $($Session:Matches.Count) Rechner erkannt." -CloseOnClick -Duration 5000
$Session:Matches | % {
$PCName = $_
$Filter += "$Session:LDAPCall{0}$Session:End" -f $PCName
}
$Session:FilterComplete = $Session:Head + $Filter + $Session:End
Set-UDElement -Id "btn-compute-input" -Properties @{ 'disabled' = $false } # enables the copy button when match is found
} else { Set-UDElement -Id "btn-compute-input" -Properties @{ 'disabled' = $true} } # disables the copy button when match is not found
}
}
# Creating UDCardFooter Button for User text input to search for Computers from ComputerList
# Button Add Groups adds the selected groups from AutoComplete-Component to the current PC in $Matches
$Session:CardFooter = New-UDCardFooter -Content {
New-UDButton -Id "btn-add-groups" -Text "Add Groups" -Disabled -OnClick {
$Session:Matches | % {
$PC = $_
$FilterPC = '(Name:IgnoreCase={0})' -f $PC
$dbComputerObject = Get-dbComputer -Filter $FilterPC -Recurse -Path 'emdb:'
$Session:GroupsToAdd | % {
$GroupName = $_
$FilterGruppe = '(cn:IgnoreCase={0})' -f $GroupName
Show-UDToast -Message "Gruppe $($GroupName) wird $($PC) hinzugefügt" -Duration 10000
$dbGroupObj = Get-dbGroup -Filter $FilterGruppe -Recurse -Path 'database:'
$dbGroupObj | Add-dbGroupMember -Member $dbComputerObject
}
}
}
}
# Paper works as <div> container for every Component in App
New-UDPaper -Id "container" -Children {
New-UDGrid -Container -Spacing 1 -Content {
# First Grid-Item (Textfield-Component)
New-UDGrid -Item -ExtraSmallSize 3 -Content {
New-UDStyle -Style $Session:Style -Content {
# Adding UDCard in first Grid-Item
New-UDCard -Header $Session:CardHeader -Body $Session:CardBody -Footer $Session:CardFooter
}
}
# Second Grid-Item (AutoComplete-Component and TransferList-Component)
New-UDGrid -Item -ExtraSmallSize 9 -Content {
New-UDDynamic -Id "dynTranserList" -Content {
# Adding Card, works as container for (AutoComplete-Component and TransferList-Component)
New-UDCard -Title "Gruppen" -Id "Card1" -Content {
# AutoComplete-Component with every Softwaregroup found in PSU Cache $ItemsRange
# Filling $Hashtable to populate Transferlist left side
New-UDAutocomplete -Options $ItemsRange -Id 'autocomplete1' -FullWidth -Label "Groups" -OnChange {
$Session:Index = $Session:Index + 1
$Session:Hashtable["$($EventData)"] = $Session:Index
Sync-UDElement -Id "dynTranserList"
}
# Export for debugging
$Session:Hashtable | Export-Clixml -Path "C:\temp\hashtable.xml"
# Populate TranserList
New-UDTransferList -Id 'transferlist-dsm-gruppen' -LeftTitle 'Choice' -RightTitle 'Add' -Item {
$Session:Hashtable.Keys | Foreach-Object {
#Show-UDToast -Message "Value: $($Value)" -Duration 5000
New-UDTransferListItem -Name $_ -Value $Session:Hashtable[$_]
}
} -OnChange {
# Populate $GroupsToAdd when Item in TransferList is put to right side
if ($EventData -ne $null) {
$Session:GroupsToAdd += $EventData.name
}
if ($Session:GroupsToAdd.Count -gt 0) {
Set-UDElement -Id "btn-add-groups" -Properties @{ 'disabled' = $false } # enable Add Group Button when Items in Transferlist are put to right side
}
}
}
}
}
}
}
}