Passing Runtime parameters to an Orchestrator Runbook

jansi rani krishnan 601 Reputation points
2021-05-21T07:42:02.04+00:00

Hi Team,

I have the “Run .Net Script” activity in one of the Runbooks, Which actually runs a PowerShell commands to send the incident information to ServiceNow using REST web services. I need to pass the credentials for authentication purpose while making the web service call. The same shell script when I run independently, it is working fine as I supply the credentials during the runtime.

I need some information on “How to pass a runtime parameters to the Runbook”, which is a sensitive information in our case. Please share the information if anyone knows how to pass the runtime parameters.

Sample code:

$CRED=get-credential
$ResponseObject=Invoke-RESTMethod -Uri $URL method 'POST' -credential $CRED -body $JsonBody -ContentType 'application/json'

Error details:

While running the runbook, it is getting failed at $CRED statement with the error "Cannot process command because of one or more missing mandatory parameters: credential"

Regards,
Jansi

System Center Orchestrator
System Center Orchestrator

A family of System Center products that provide an automation platform for orchestrating and integrating both Microsoft and non-Microsoft IT tools.

0 comments No comments

Answer accepted by question author
Andreas Baumgarten 133.1K Reputation points MVP Volunteer Moderator
2021-05-21T08:49:13.877+00:00

Hi @jansi rani krishnan ,

it's possible to store sensitive data like passwords as an encrypted variable in Orchestrator.
I am using two variables for this, it's easier to maintain later (UserName and UserPassword)
Make sure to select the Encrypted Variable checkbox for the UserPassword.

98510-image.png

In your PowerShell script replace $CRED=get-credential with these lines.

$UserName = "UserName"  
$PassWord = ConvertTo-SecureString -String "UserPassword" -AsPlainText -Force  
$CRED = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName, $PassWord  

In your PowerShell script you could subscribe to the variables (replace the hardcoded values) .

98466-image.png

The result should look like this:

98581-image.png

----------

(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.