Displaying output from a job in a page

Product: PowerShell Universal
Version: 2.3.1

Hello,

I’m trying to display an output from a job by clicking a button. When I click it nothing happens. I’m not really sure why something so simple just doesn’t work. I’ve granted the app token to the dashboard and while I’ve gotten this type of thing to work in other dashboards I can’t seem to get it working in this one.

The script runs on a schedule and I’d like to display the results in my dashboard.

Not going to lit PSU can be pretty frustrating at times.

Code:

    New-UDElement -Tag 'div' -Id 'Results'

    New-UDButton -Text 'GO' -OnClick {
        Set-UDElement -Id 'Results' -Content {
        $Job = Get-UAScript -Name 'myscript.ps1' | Get-UAJob -OrderDirection Descending -First 1
        Get-UAJobOutput -Job $Job
        }
    } 

Thank you

I hate hearing that PSU is frustrating.

I don’t know exactly what is causing this issue and I’ll dig in a bit more tomorrow.

I just wanted to drop an issue for your here to give some hope: Invoke jobs without app token from dashboard · Issue #573 · ironmansoftware/issues · GitHub

We have been working to remove the requirement of having PSU app tokens in dashboards. We have some of the plumbing done to achieve this but it isn’t prod ready. That said, I’ve moved this into the PSU 2.5 release.

My main goal is to be able to call several frequently used cmdlets without tokens so it “just works”.

This should just be possible:

$PipelineOutput = Invoke-PSUScript "MyScript" -Wait
Show-UDToast $PipelineOutput 

Just wanted to drop some ideas on the vision going forward and I’ll follow up tomorrow with some debugging steps.

1 Like

Thanks Adam, you’re always on point with the support and one of the main reasons I keep going. Overall I do like PSU and want use it for every day admin work but every time I try something I hit some roadblock that requires some extensive reading of your documentation, checking the forums, or googling. I hope this platform continues to grow because I see what probably everyone sees on here. A great tool that can disrupt how we work!

After looking at this with fresh eyes, I wonder if it’s because of the data type returned by Get-UAJobOutput.

What happens when you access the data parameter?

    New-UDElement -Tag 'div' -Id 'Results'

    New-UDButton -Text 'GO' -OnClick {
        Set-UDElement -Id 'Results' -Content {
        $Job = Get-UAScript -Name 'myscript.ps1' | Get-UAJob -OrderDirection Descending -First 1
        (Get-UAJobOutput -Job $Job).Data
        }
    } 

This is the type returned from Get-UAJobOutput.

    public class JobOutput : IModel
    {
        public long Id { get; set; }
        public string Message { get; set; }
        public JobOutputType Type { get; set; }
        public string Data { get; set; }
        public Job Job { get; set; }
        public DateTime Timestamp { get; set; }
    }
1 Like

That definitely did the trick! Now to figure out the formatting. There’s no line breaks. Any advice?

I think the problem is that it’s an array of strings. Try join them with an new line.

(Get-UAJobOutput -Job $Job).Data -join "`r`n"

So I have to apologize. I was able to get it working the way i liked. Just had to think in PSU terms. Thank you for your support!

Feel free to elaborate on your solution - might help others in the future :slight_smile:

Oh sure, so I in the mindset of trying to display the output of a simple get-childitem command in PSU as a table so I was using the Get-UAJobOutput. This would get the output in an unformatted fashion.

When working in PSU a lot of the formatting and legwork is already done for you, you just have to think like how PSU wants you to.

So I just grabbed the pipeline output and threw it in a table which worked exactly how I wanted. Below is the code.

Before:

    $Job2 = Get-UAScript -Name 'Test2.ps1' | Get-UAJob -OrderDirection Descending -First 1
    (Get-UAJobOutput -Job $Job2).data

After:

    $Job2 = Get-UAScript -Name 'Test2.ps1' | Get-UAJob -OrderDirection Descending -First 1
    $jobData2 = (Get-UAJobPipelineOutput -Job $Job2)
    New-UDTable -Id 'TestTable2' -Data $jobData2 -Title 'Test' -Dense

Once that clicked in my head everything made much more sense. PSU is a great tool, but it certainly requires you to fully understand what you are trying to do in terms of how PSU does things. It can be frustrating at times but thankfully we have great support in Adam and some pretty good documentation so that helps a lot.

Hope this helped you!

3 Likes

What if your script takes parameter?
How do you pass that in this scenario?