Orchestration - PowerShell - passing credentials as a PowerShell variable

juriggs
Kilo Expert

I have several scripts that are connecting to O365 which require passing credentials. Currently, for testing, I am just sending the username and password inputs as Strings. Obviously, for prod, I need to encrypt the password so it doesn't show up in the logs. What is the proper procedure for doing this? Can I pass a credentials object to the script through the PowerShell variables section of the Execution Command tab of the Activity?

Thanks.

1 REPLY 1

Robert Beeman
Kilo Sage

PowerShell selects a "Windows" type Credential from your Credential (discovery_credentials) table in ServiceNow (or runs as your MID Servers service account) and passes the credential into the script as the $cred variable. You can use the $cred in your script like this:

Get-WmiObject -Credential $cred -Class "Win32_Service"