SOLVED - New-UDInput questions

So first of all. I LOOOOVE UD. So much that I bought a license just to replace my GUI powershell support tools with a version all done in UD. So far so good. However I’m running into an issue or maybe I’ve reached the limitations of the prodcut. Here is what I am doing.

Im taking a list of Collections from SCCM and want to use them as the values in a New-UDInputField but not sure how to import them into the values field. Might not even be a UD issue but a powershell issue.

$collections = Get-CimInstance -ComputerName $SITESERVER -Namespace "root\sms\site_$site" -ClassName "sms_collection" -ErrorAction Stop | select Name,CollectionID,ObjectPath,comment | Sort-Object Name
$collections = $collections | where {$_.comment -like "!include*"}
New-UDInputField -Type select -Name "sccmcollection" -Placeholder "Choose your Collection" -Values @("$collections.name")

Here is another example, basically trying to populate the select field with ad groups from a text file.

New-UDInput -title "Machine AD Groups (Coming Soon)" -SubmitText "Add" -content {
$machinegroups = Get-Content D:\ud\MachineGroups.txt -Force
New-UDInputField -Type 'textbox' -Name 'adaddcomputer' -Placeholder "Computer Name"
New-UDInputField -Type select -Name "adgroupsinput" -Placeholder "Choose your action" -Values @()   
} -Endpoint {
}

First off, welcome to the community!

Just out of curiosity, what does your code currently output? From what I can tell, you’re going to get a single option in the dropdown that is actually your array of names separated by spaces. Have you tried something like this?:

New-UDInputField -Type select -Name "sccmcollection" -Placeholder "Choose your Collection" -Values $collections.name

It outputs a table but i modified it to only give me the name of the collection in the $collections variable. Just not sure that would work. I have however gone around it for now and created a new dynamic page.

Hi Bacon,

I took a look at the SCCM query since I don’t know how you formatted the text file. I was able to get it to work with the code you provided. What does the drop-down list give you? Mine presents me a dropdown populated with a list of all the collection names.

$Dashboard = New-UDDashboard -Title "Test" -Content {
New-UDColumn -Size 6 {
            New-UDInput -Title "List SCCM collections" -SubmitText "Choose Group" -Content {
                $collections = Get-CimInstance -ComputerName $sccm -Namespace "root\sms\site_$site" -ClassName "sms_collection" -ErrorAction Stop | select Name,CollectionID,ObjectPath,comment | Sort-Object Name
                New-UDInputField -Type select -Name "sccmcollection" -Placeholder "Choose your Collection" -Values @($collections.name)
            } -Endpoint {
            New-UDInputAction -Toast "It worked"
            }
               
        } 

}


Start-UDDashboard -Dashboard $Dashboard -Port 8080

-Obie

i get a list of all the collection names, however its ONE item, not individual items. For the sake of sanity I have just put a list in a text file and done get-content so its a list of just the names, same result.

Mine is selecting an individual collection.

For the endpoint are you doing a param where you pass in the name of the Input field to use as the individual selection

$Dashboard = New-UDDashboard -Title "Test" -Content {
New-UDColumn -Size 6 {
            New-UDInput -Title "List SCCM collections" -SubmitText "Choose Group" -Content {
                $collections = Get-CimInstance -ComputerName $sccm -Namespace "root\sms\site_$site" -ClassName "sms_collection" -ErrorAction Stop | select Name,CollectionID,ObjectPath,comment | Sort-Object Name
                $collections = $collections | where {$_.comment -like '*'}
                New-UDInputField -Type select -Name "sccmcollection" -Placeholder "Choose your Collection" -Values @($collections.name)
            } -Endpoint {
            param($sccmcollection)
            New-UDInputAction -Toast "It worked, you selected $sccmcollection"
            }
               
        } 

}
Start-UDDashboard -Dashboard $Dashboard -Port 8080

Nope just one big blob of text, here ill show you my code im using to test with. I have a text file, 1 group per row.

Get-UDDashboard | Stop-UDDashboard
$Dashboard = New-UDDashboard -Title "Test" -Content {
    New-UDColumn -Size 6 {
        New-UDInput -title "Machine AD Groups (Coming Soon)" -SubmitText "Add" -content {
            $machinegroups = Get-Content D:\ud\MachineGroups.txt -Force
            New-UDInputField -Type 'textbox' -Name 'adaddcomputer' -Placeholder "Computer Name"
            New-UDInputField -Type select -Name "machinegroup" -Placeholder "Choose Machine Group" -Values @("$machinegroups")   
        } -Endpoint {
            param($adaddcomputer,$machinegroup)
            New-UDInputAction -Toast "You added $adaddcomputer to $machinegroup "
        }
           
    } 
}
Start-UDDashboard -Dashboard $Dashboard -Port 8080

Imgur
Imgur
Imgur

It seems if i get the AD groups or SCCM Collections as objects with a header such as Name, then call $variable.name in the Values field it works just fine. However just importing a list from a text file with no header doesnt work and just makes it one big field.

Drop the quotes on: @("$machinegroups") and it worked for me you are putting an array within a string at that point.

New-UDInputField -Type select -Name "machinegroup" -Placeholder "Choose Machine Group" -Values @($machinegroups)