PSU 5.0.5 and 5.0.6 - Invoke-PSUScript errors

In the clean install of PSU 5.0.5 I stood up earlier for my testing, I’ve now found that Invoke-PSUScript seems to have an issue with locating scripts or accessing scripts when using the -Script operator.

If I create a script at the root of my repository (let’s name it Testing.ps1), and I then reference the script in an Endpoint via Invoke-PSUScript -Name 'Testing.ps1' - TrustCertificate the invokation runs without an issue.

If I create a script in a subfolder of my repository (for example, the folder is named Test Scripts, and the script is named Testing.ps1), and I reference it in an Endpoint via Invoke-PSUScript -Name 'Test Scripts\Testing.ps1' - TrustCertificate the invokation fails because -Name doesn’t support paths/folders (you get Cannot retrieve the dynamic parameters for the cmdlet. Unknown script: Testing\Testing.ps1 if you attempt to use a folder).

Given that -Name doesn’t support paths/folders, if I were to have 2 scripts named identically but in different folders, I would never be assured of which script the -Name operator would end up running, so this leaves me with having to use the -Script operator instead and illuminates its new (as of 5.0.x) behavior.

If I create a script in a folder or subfolder of my repository (for example, the folder is named Test Scripts, and the script is named Testing.ps1), and I reference it in an Endpoint via Invoke-PSUScript -Script 'Test Scripts\Testing.ps1' - TrustCertificate I get the error Cannot retrieve the dynamic parameters for the cmdlet. Object reference not set to an instance of an object. when accessing the API.

Did something change from 4.x to 5.x in regard to Invoke-PSUScript?

For reference, I’ve already tried variations of the path without any success.

Product: PowerShell Universal
Version: 5.0.5

The path\name issue should be resolved. I’ll open an issue for that. No reason for that behavior to change.

As for the API endpoints calling scripts, it looks like permissive mode isn’t working properly in apps and APIs. I have a fix in for this and should be working in 5.0.6.

1 Like

PSU 5.0.6 did fix the -Name operator’s support for paths on the Invoke-PSUScript cmdlet, but there is still an issue with the -Name and -Script autocomplete funtionality.

If your Invoke-PSUScript line uses PSU’s autocomplete when selecting the script to run.

For example, if you begin typing the path and name of a script, such as Testing\ and then pick the script from the popup dialog, you end up with something that looks like Invoke-PSUScript -Script 'Testing\'.\Testing\Testing.ps1' -TrustCertificate because the autocomplete feature doesn’t just add the remaining text - it appends the entire path. Accounting for this issue, if you strip off the part you typed manually, you would end up with Invoke-PSUScript -Script '.\Testing\Testing.ps1' -TrustCertificate but attempting to run the command results in:

Cannot retrieve the dynamic parameters for the cmdlet. Object reference not set to an instance of an object.
at <ScriptBlock>, <No file>: line 2
at <ScriptBlock>, <No file>: line 1

If you take the .\ off of the path (e.g., Invoke-PSUScript -Script 'Testing\Testing.ps1' -TrustCertificate), the command runs fine.

For reference, the -Name operator’s autocomplete has the same bug with the path being incorrectly appended, and results in the same error if you use the invalid autocomplete path.

1 Like

I opened a couple issues for these items. Should be able to get them done in 5.0.7

2 Likes

Just upgraded my test environment to 5.0.7 (from 5.0.6) and it did fix the issues with Invoke-PSUSCript’s auto-complete path issues as well as fixing TrustCertificate when defined in appsettings.json so adding it per-script/API is not needed.

I can confirm that.

1 Like