Getting a "Bad gRPC response" from Invoke-PSUScript

Product: PowerShell Universal
Version: 5.5.1

Hello everyone

I have a main script that combines tenants and then executes another script for each tenant using the Invoke-PSUScript command.
Main:

foreach ($tenantName in $tenantNames)
    {
        $psuJob = Invoke-PSUScript -Script 'Tenant.ps1' -TenantName $tenantName
    }
}

The Error i get then, when the Script is executed with the PSU Scheduler:

Cannot retrieve the dynamic parameters for the cmdlet. Status(StatusCode="Cancelled", Detail="Bad gRPC response. Invalid content-type value: text/html; charset=utf-8")

The script worked in the previous version of our installed PSU (v.4) and was executed as desired.
Also, when i start the Script on the Webinterface from PSU it works like a charm.

When I looked up the error in the search engine and read the comments, I had the idea that it might have to do with the classes and the preloading of the script, which is why I packed the whole second script into functions and then execute them, or packed the entire classes into a *.dll and integrate them into the script.

I can’t remember exactly what I’ve already tried but i have no idea anymore.
So any help is appreciated.
Best Regards
Tom

This could possibly be the same issue I reported a few days ago, but it could also be the changes in how PSU talks internally and can depend on how (where) your scripts are being used at. For example, if they’re being called as part of a scheduled task, those jobs don’t run in a user context, so you have to add some lines within the script the task executes that tells it to connect to PSU internally using an App Token that has access to whatever resources are needed (secrets, scripts, APIs, etc.).

Create an app token for an identity that has admin access to PSU (or at least has access to the secrets you need to reference below), and then add the following to the top of your script (before any lines that attempt to access secrets) being called in your scheduled task:

$AppToken = <redacted>
Connect-PSUServer -AppToken $AppToken -ComputerName 'https://<redacted>'

Or, if you prefer not to have your app token and FQDN defined within the script directly, you could create a non-secret (standard) variable in PSU that contains the app token and another that contains the PSU FQDN, and then you could do:

Connect-PSUServer -AppToken $PSUInternalToken -ComputerName $PSUFQDN

Hello Jesse
Thank you very much for your reply.
I have also seen the post, but thought that this cannot be the solution to my problem for the following reason:
We have installed PSU with the .msi, it runs the Windows Service “Powershell Universal” as Local System.
I don’t need a Connect-PSUServer for any of the scripts as they are executed directly.
Or am I missing something important here?
If your workaround would solve the problem for the time being and the PSU Scheduler could start the scripts correctly again, that would be a huge help, but I’m not sure where to start here. Can you guide me here?

The MSI version of the installer, versus any of the other types of installers, changes nothing about what I said. PSU communicates within itself using gRPC (at least by default). When you run a script manually (as in, you’re logged into the admin console and you launch a script), it runs as your account or in a user context, so it has whatever permissions your account has access to.

When you run a script as a part of a scheduled task, the script is NOT executed in a user context and has no inherent permissions. So, you have to use Connect-PSUServer with an app token for an account that has permission to all of the required resources in PSU in the script the scheduled task executes.

Hi Jesse

Thank you for pushing me to the right direction.
I added, as you mentioned, in my main script:

Connect-PSUServer -AppToken $PSUInternalToken -ComputerName $PSUFQDN

Now it runs through without:

Cannot retrieve the dynamic parameters for the cmdlet. Status(StatusCode="Cancelled", Detail="Bad gRPC response. Invalid content-type value: text/html; charset=utf-8")

Best Regards
Tom

1 Like