New-UDInput with file option

I am trying to build a form where you fill in some parameters that get saved as variables. The last piece is to upload a text file with a list of servers. I am saving that as a variable but when i try to use the variable in a foreach loop its not going through each server in the text file. Am I missing something silly?

New-UDInput -Title “Please Enter Information Below” -Id “Form” -Content {
New-UDInputField -Type ‘textbox’ -Name ‘name’ -Placeholder “name”
New-UDInputField -Type ‘textbox’ -Name ‘description’ -Placeholder “description”
New-UDInputField -Type ‘textbox’ -Name ‘start’ -Placeholder “start”
New-UDInputField -Type ‘textbox’ -Name ‘stop’ -Placeholder “stop”
New-UDInputField -Type file -Name ‘serverlist’ -Placeholder “Add Serverlist File”

} -Endpoint {
    param($name, $description, $start, $stop, $serverlist)


foreach ($server in $serverlist) {
do some stuff
}

thanks

$serverlist is a file object. You need to do a get-content on it.
eg $servers = get-content $serverlist

gav

i tried changing it to this but now in the debug log i can see it trying to pick the server from the path on my machine. Should I be trying another way to grab take the uploaded file .

2:44:20 [Warn] PowerShellExecutionService Error executing endpoint Form. Cannot find path ‘C:\Windows\System32\WindowsPowerShell\v1.0\SERVER1’ because it does not exist.
at , : line 4
12:44:20 [Warn] PowerShellExecutionService Error executing endpoint Form. You cannot call a method on a null-valued expression.
at , : line 12


New-UDInput -Title “Please Enter Information Below” -Id “Form” -Content {
New-UDInputField -Type ‘textbox’ -Name ‘name’ -Placeholder “name”
New-UDInputField -Type ‘textbox’ -Name ‘description’ -Placeholder “description”
New-UDInputField -Type ‘textbox’ -Name ‘start’ -Placeholder “start”
New-UDInputField -Type ‘textbox’ -Name ‘stop’ -Placeholder “stop”
New-UDInputField -Type file -Name ‘serverlist’ -Placeholder “Add Serverlist File”

} -Endpoint {
param($name, $description, $start, $stop, $serverlist)

$serverobj = get-content $serverlist
foreach ($server in $serverobj) {
do some stuff
}

Do i need to open and or stream the contents of the file so i can process it? What is the difference between File and BinaryFile Types?

New-UDInput -Title “Please Enter Information Below” -Id “Form” -Content {
New-UDInputField -Type ‘textbox’ -Name ‘name’ -Placeholder “name”
New-UDInputField -Type ‘textbox’ -Name ‘description’ -Placeholder “description”
New-UDInputField -Type ‘textbox’ -Name ‘start’ -Placeholder “start”
New-UDInputField -Type ‘textbox’ -Name ‘stop’ -Placeholder “stop”
New-UDInputField -Type binaryfile -Name ‘serverlist’ -Placeholder “Add Serverlist File”

} -Endpoint {
param($name, $description, $start, $stop, $serverlist)

$fileStream = [IO.File]::Create($serverlist.FileName)
$stream = $serverlist.OpenReadStream() 
$stream.CopyTo($fileStream) 
Get-Content $stream
$fileStream.Dispose()

I got it. Not sure if it was the best way to do it but i used the filestream to store the file locally on my machine. The i do a get-content on it, run through the loop and then delete the file. For some reason i thought the uploaded file would be stored in a variable and I just go through a loop from it like that.

I see the problem now. $serverlist is a string of text file content.
Try splitting by “new line” and cleaning up excess characters.

...
New-UDInputField -Type file -Name ‘file’ -Placeholder “Add Serverlist File”
} -Endpoint {
param($name, $description, $start, $stop, $file)
	$serverlist=($file.Split("`n")).trim()
	foreach ($server in $serverlist) {
		do stuff
	}
}

gav