Getting a "Bad gRPC response" from Invoke-PSUScript

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