I followed the notes in the ticket below in attempts to execute a script with the specified set of credentials that are stored as a secret variable, but the script is still being executed with the account that is running the PowerShell Universal Windows server (listed under “logon as”) instead of the referenced credentials. The job status displays "run manually by “ServiceAccount” in the Integrated environment as “userAccountName” and the output results of the script show “ServiceAccount” as the user actually executing the script.
I’m trying the following (the users credentials is stored as a secret variable):
With that being said, my script is executing successfully, but not executed as the end user. I’m using the code below but $env:USERNAME inside of the script being invoked is the account running the Windows Service instead of the user account. The job description makes it appear that it executed successfully "run manually by serviceAccountName in the 7.1.3 environment as User1. However the output shows it executed as the service Account.
Update: $env:USERNAME is still evaluating to the service account, however “whoami” is evaluating to the user… the main focus is figuring out how to pass the PSCredential object into the script so that I can create PSSessions with the user’s account.
I’ve attempted to pass the PSCredentials as follows but it does not appear to be passing them to the script file successfully:
The code above is working correctly for me. I needed to allow the script being invoked to run and understand that $User continues to evaluate to the service account, but everything in the script is in fact executing with the credentials specified in the (Get-UAVariable -name ‘User1’) variable. This was confirmed by storing the current user with “whoami”.