Passing a PSCredential into a script using a schedule

Product: PowerShell Universal
Version: 2.8.1

I’m experimenting with using PowerShell Universal to run a script to get status information from another application. I need to authenticate with the application using custom credentials, so the script has a pscredential parameter and when I run the job manually, it works fine.

When I create a schedule, and select the pscredential variable to pass to the script, I get an error:

Error Deserializing C:\ProgramData\UniversalAutomation\Repository\.universal\schedules.ps1
Cannot process argument transformation on parameter 'VmsCredential'. A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: Enter your credentials.

The VmsCredential parameter is defined as a secret variable of type PSCredential and the entry in schedules.ps1 looks like…

New-PSUSchedule -Cron "* * * * *" -Script "Camera Report.ps1" -TimeZone "America/Los_Angeles" -Credential "Default" -VmsCredential 'MilestonePSTools' -ServerAddress 'http://joshooaj' -BasicUser -Name "Test"

This is a bug. You should be able to pass in credentials like this.

One work around would be to use Get-Variable to grab the credential variable by name in the script. The script will receive the $MilestonePSTools credential variable automatically since it is defined in the PSU variables.

param($VmsCredential)

$Credential = Get-Variable $VmCredential -ValueOnly

1 Like

That worked, thanks!