Calling PowerShell script from New-UDInputAction

Hi all,

I’m new to Universal Dashboard, and figuring it all out. I can’t seem to figure out how to start a separate PowerShell script when New-UDInputAction is clicked. Here is my code so far, personal details taken out.

$MyDashboard = New-UDDashboard -Title "Automation Provisioning" -Content {
   
    New-UDInput -Title "Pre-Verify Build" -Id "Form" -Content {
        New-UDInputField -Type 'textbox' -Name 'vc' -Placeholder 'vSphere'
        New-UDInputField -Type 'textbox' -Name 'cluster' -Placeholder 'Cluster'
        New-UDInputField -Type 'textbox' -Name 'template' -Placeholder 'Template'

        } -Endpoint {
            param($vc, $cluster, $template)

            New-UDInputAction -Endpoint {
                

                C:\Users\myuser\Desktop\UDDashboard\pre-VerifyProvision.ps1 -vc $vc -cl $cluster -template $template
                
            }
        }

}

$cert = ( Get-ChildItem -Path cert:\LocalMachine\My\############ )

Get-UDDashboard | Stop-UDDashboard
# Enable-UDLogging
# Disable-UDLogging
Start-UDDashboard -Port 8080 -Dashboard $MyDashboard -Certificate $cert #-AutoReload

Calling full path of the other script cause $PSScriptRoot doesn’t work for me for some reason.

Here is the debug:
[Warn] ExecutionService Error executing endpoint script. Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together
or an insufficient number of parameters were provided.
at , : line 11
15:24:54 [Debug] ComponentController ConvertToActionResult() {“Error”:{“message”:“Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.”,“location”:null,“type”:“error”,“id”:null,“refreshInterval”:0,“autoRefresh”:false,“hasCallback”:false}}

Those are the right parameters for my script though. Anyways my project is I already have existing scripts for a project, I’m just trying to use Universal Dashboard to put it all together and more presentable.

As a side question. Can the script output once clicking submit be displayed on another card below the form using Set-UDElement and New-UDElement?

Any help greatly appreciated.

Realized my error, I realized later the first endpoint is when the user actually click submit. Not the second one.

My new code is this:

    $verify = C:\Users\user\Desktop\UDDashboard\pre-VerifyProvision.ps1 -vc $vc -cl $cluster -template $template 

                if ($verify)
                {

                    New-UDInputAction -Content @(
                    New-UDCard -Title "Verify Status" -Text "$verify"
                    )

                }

That came back as true. I guess my question is I have alot of Write-Host in the script being called that would be nice to see on the dashboard. How can I see the Write-Host output on the dashboard?

I believe you would have to have your write-host as write-output or get the values to a variable and show it there. Write-host only shows the text in the powershell session.

Thanks @TmJr75, that helped push me in the right direction, now I’m facing this issue.

Please see this post: Anyway to keep spaces and line breaks in UD?

Hi,

I want to do the same thing. Can you share with us how can you display Write-Output on the webpage ?

I have been using

                    {Show-UDToast -Message $variable -duration 600000
                    }

to do the equivalent of Write-Host