Output from Pipeline for Import Scripts

We have about 20-30 import scripts that have been converted to powershell universal scripts. Each one takes between 1 min and 5 minutes to run and imports between 300 and 10000 records into a SQL database. The scripts in powershell universal run fine and we can see the output in the pipeline when we use the script function in powershell universal. Using the dashboard we want to have each import script have a button so the non technical user can click import and then see the pipeline or at least some level of progress of the import. I can’t seem to find the right documentation on how to accomplish something like this. Right now I can make a button run the right script but i can’t seem to find how to output the pipeline from the script to a real time window or other progress bar or something that lets the user know the import is in progress. Can you point me to the best method.

There are a couple ways to accomplish this. The simplest would be to include Write-Progress in your script. Invoke-PSUScript with the -Wait parameter will then display that progress in the dashboard automatically. I would also include -ShowLoading in the button to give some feedback on the button that something has started to happen.

New-UDButton -Text 'Start' -OnClick {
      Invoke-PSUScript -Name 'MyScript' -Wait | Out-Null
} -ShowLoading

If you want to get feedback from the script as it is running, it’s a bit more complicated since you’ll need to loop and check for new output.

New-UDButton -Text 'Start' -OnClick {
      $Job = Invoke-PSUScript -Name 'MyScript' 
      while($Job.State -eq "Running")
             $Session:PipelineOutput = Get-PSUJobPipelineOutput -Job $Job
             Sync-UDElement -Id 'output'
             $Job = Get-PSUJob -Id $Job.ID 
             Start-Sleep 1
} -ShowLoading

New-UDDynamic -Id 'output' -Content {
      New-UDTypography "We've output $($Session:PipelineOutput.Length) things"