Invoke-UAScript encounters HTTP 404

I’m sorry to be back asking questions so quickly. I would prefer to be able to figure this out myself but either I’m missing something in the documentation, or the documentation isn’t covering the basics.

All I’m trying to do is run a script while passing it a parameter then populate a table using the object that it returns.

I would really appreciate your help with this. I’m assuming that when I figure out how to call scripts, I will then be able to move onto calling the last job output. I have a few scripts that take up to 5 minutes to return data so I think the scheduler is going to be perfect for this situation.

The command is as follows:

$GroupMembership = Invoke-UAScript -Script 'script:GetGroupMembershipForUser.ps1' -AppToken $AppToken -ComputerName 'http://localhost:5000'                                                                                                 

Invoke-UAScript: Call failed with status code 404 (Not Found): POST http://localhost:5000/api/v1/script/0

I know that the script name is correct.

I got the idea to use invoke-UAScript from here:
Management API - PowerShell Universal (ironmansoftware.com)

Here is the full code:

New-UDForm -content {
    New-UDTextbox -Id "Username" -Label "Username" -Placeholder Username
} -OnSubmit {        
    $UserDetails Invoke-UAScript -Name 'GetUserDetails.ps1' -UserName $EventData.Username
    New-UDTable -Id"UserDetails" -Data $UserDetails
}

Hi @Darragh,

Invoke-UAScript won’t return data itself. Here’s an example of invoking a script and waiting for it to complete.

You can use Get-UAJobPipelineOutput to retrieve the pipeline output after the job has completed.

 Invoke-UAScript -Name 'GetGroupMembershipForUser.ps1' -DistinguishedName $Item.DistinguishedName | Tee-Object -Variable job | Wait-UAJob
Get-UAJobPipelineOutput -Job $Job

That said, it seems like we could enhance Invoke-UAScript to wait and return all in one command to avoid having to issue all three commands. I’ll add that to our backlog.

In terms of why you are getting a 404, I’m not sure what’s happening there. It would seem that as long as you have the name correct it should be finding the script. Can you please share a debug log (found in %ProgramData%\PowerShellUniversal) to see if I can help spot anything that might be happening there?