Creating a table of existing jobs to display for users: Invoke-PSUScript has no output?

Hello everyone, I am fairly new to PU and powershell in general so any help is apreciated.
I am trying to display some scripts for the enduser made in PU via a table. The problem I am currently facing is that I try to collect some kind of data when running a script which I can use to disable all Buttons while this job is running. But it seems there is no Output I can use from Invoke-PSUScript or Get-PSUJobOutput.

$Columns = @(

New-UDTableColumn -Property run -Title 'Ausführen' -Width 5 -Render {
    $Page:Icon = New-UDIcon -Id "DynIcon" -Icon playcircle -Size 1x
    $Page:RunButtons = New-UDButton -Id "btn$($EventData.Skriptname)" -Icon $Page:Icon -OnClick {

        $outscript = Invoke-PSUScript -Name $EventData.Skriptname # -Wait
        $outscript | Out-File -Path "C:\_temp\debugfiles\outscript.txt"
        
        # this is some pseudocode I am trying to achieve
        if ($outscript) { $jobdone = $true }
        while(!$jobdone) {
             Set-UDElement -Id "btn*" -Properties @{ disbale = $true }
             if ($jobdone) { 
                  Set-UDElement -Id "btn*" -Properties @{ disbale = $false }
                  break
             }
        }
        
        # Output loggen
        $Job = Get-PSUScript -Name $EventData.Skriptname | Get-PSUJob -OrderDirection Descending -First 1
        #$Pipe = Get-PSUJobPipelineOutput -Job $Job
        $JobOutput = Get-PSUJobOutput -Job $Job  
        $JobOutput | Out-File -Path "$($Page:LogPath)\$($Page:Date)_$($EventData.Skriptname)_Output.txt"
        
       
    }
    $Page:RunButtons 
}     
New-UDTableColumn -Property Skriptname -Title "Skriptname" -IncludeInSearch
New-UDTableColumn -Property Beschreibung -Title "Beschreibung"

)

$outscript has no value which I would try to use as a bool value to run a while-loop

Try using the Get-PSUJob command instead. If I remember correctly, that has the info you’re looking for.

I would also avoid trying to use a while-loop. Instead read up on Universals amazing UDDynamic instead.

Hey, thanks for the tips. I tried UDDynamic earlier last week to change the Icon of the buttons when a Job is running but the Buttons inside the table didnt update for some reason. I managed to get a working UDAutoComplete with a dynamic list beneath it in another project which worked fine but tables dont. The Get-PSUJob cmdlet also only gave me the output when the job was done. So I couldn’t grab the “runningstate” to update the icons.
I may have had the -wait parameter on Invoke-PSUScript, I’ll give it another try.
All in all, this is why you see my workaround above.

I just found this where a user has the same problem and calls it a bug?

Get-PSUJob gives me the exact state of the job…

CreatedTime        : 21/10/2024 13:09:49
StartTime          : 21/10/2024 13:09:49
EndTime            : 01/01/0001 00:00:00
Status             : Running
...```
1 Like

Not exactly a bug, but it’s how it functions under the hood.

The solution is written out in the reply on that post!