New-UDInputField -Type 'select' -Name 'Servers' -Values @($servers) Help Needed

Hi guys,

i was wondering about the difference of the following

if setup a variable this way

$servers = “server1”,“server2” and use it in New-UDInputField as

New-UDInputField -Type ‘select’ -Name ‘Servers’ -Values @($servers)
it works fine but if i did it like

$servers = get-content -file … etc where i end up with same exact results like this output
PS C:\Users\Admin\Desktop> $servers
server1
server2

and tried to use
New-UDInputField -Type ‘select’ -Name ‘Servers’ -Values @($servers) it does not work

any reason why???

-Values $Servers

No need for the @()

@Jacob-Evans
i have tried your idea and still not working.

i want to add it this way
New-UDInputField -Type ‘select’ -Name ‘Servers’ -Values “Select Server” , $servers
and when i do it this way i got all servers as one object.

Yeah, you changed what you are doing from what you posted before and changed from what I suggested, when you added “Select Server”, you told powershell to treat $servers as a string instead of an array.

before i add the select server , my servers names showed up correct but could not use any of them they just look like empty.
but if you want to add select server and have it work why needs to be done here?

if i did it -values “select server”,“server1”,“server2” it works but does not work “select server”,"$servers" or
-values $servers or -values “$servers”

Take this working code:

$Dashboard = New-UDDashboard -Title "Test Select Form" -Content {

    $ServerList = @('Select Server')

    $ServerList += @(Get-Content "C:\Users\augustin.ziegler\Downloads\UD_server.txt")

    New-UDInput -Title "Test Select Form" -Content {

        New-UDInputField -Type 'select' -Name 'Servers' -Values $ServerList

    } -Endpoint {

        param($Servers)

        New-UDInputAction -Toast "Selected Server: $Servers"

    }

}

Get-UDDashboard | Stop-UDDashboard

Start-UDDashboard -Dashboard $Dashboard -Port 10002

UD_server.txt

server1
server2

1 Like