question

jansiranikrishnan-1796 avatar image
0 Votes"
jansiranikrishnan-1796 asked AndreasBaumgarten commented

Passing Runtime parameters to an Orchestrator Runbook

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

msc-orchestrator
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered AndreasBaumgarten commented

Hi @jansiranikrishnan-1796 ,

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



image.png (117.1 KiB)
image.png (81.2 KiB)
image.png (56.8 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Andreas,

Excellent.. This is perfectly working. Thank you so much.

Regards,
Jansi

0 Votes 0 ·

Hi Jansi,

you are welcome :-)
Thanks for the feedback.


Kind regards
Andreas Baumgarten

0 Votes 0 ·