Cannot convert the "System.Management.Automation.PSCredential" value of type "System.Management.Automation.PSCredential" to type "PowerShellUniversal.Variable"

i’m trying to invoke a ps1 script using Invoke-PSUScript, the steps leading to having a secured credential being passed are correct but for some reason - it always comes back to me with an error found below. anyone has encountered this? i’d appreciate the help.

Invoke-PSUScript -Script QueryConnectionBrokerCollection.ps1 -RequiredParameter $ConnectionBroker -Credential $cred

Cannot convert the “System.Management.Automation.PSCredential” value of type “System.Management.Automation.PSCredential” to type “PowerShellUniversal.Variable”

Is -Credential a parameter in your script that you are trying to call? If so, we currently don’t support passing credentials with Invoke-PSUScript. We do have an open issue for this. Additionally, you would need to rename it because it conflicts with the built-in runas support credential parameter.

If you’re trying to use the built-in runas credential parameter, then you will need to define a variable and reference that.

Invoke-PSUScript is expecting a variable and not a credential. The variable should be defined in the secret store and PSU will look it up from there.

For example, you would have to create a secret variable.

And then when you run the script, use the variable name rather than the secret directly.

Invoke-PSUScript -Script QueryConnectionBrokerCollection.ps1 -RequiredParameter $ConnectionBroker -Credential "MyStoredCredential"

thanks adam!

i get it - correct me if i’m wrong - now it got me thinking, i can call multiple ps1’s using different elevated accounts (without changing the runas account and set to default) but i just have to create multiple stored creds needed per ps1, right? like the ones below…

Invoke-PSUScript -Script script1.ps1 -RequiredParameter $param1 -Credential “MyStoredCredential1”

Invoke-PSUScript -Script script2.ps1 -RequiredParameter $param2 -Credential “MyStoredCredential2”

Invoke-PSUScript -Script script3.ps1 -RequiredParameter $param3 -Credential “MyStoredCredential3”

Yep. Exactly!



image

although i know i’m in the right direction but i get that error above. i have the DB settings unchanged, i set the variable under PSUSecretStore - so i have the ps1 stored under the DB’s folder and also in the scripts folder

C:\ProgramData\UniversalAutomation\Repository\dashboards\GPDS
C:\ProgramData\UniversalAutomation\Repository\Scripts

i also checked all necessary accounts have full control on the ps1 - is there anything i’m missing?