Orchestration - PowerShell - passing credentials as a PowerShell variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2019 09:00 AM
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.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2019 10:05 AM
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"