How to pass arguments from ServiceNow payload to powershell script via windows scheduled task?

User485076
Tera Contributor

I have a scheduled task that is running a powershell script. I need to pass some arguments to it from ServiceNow. You see below that arg0 and arg1 are in the payload. I need to set these to $UserName and $ComputerName in the powershell script. The script is running but these are not getting set. When I log, it just sets them to $arg0 and $arg1 as strings. Can anyone help?

 

Payload sent:

User485076_0-1715869188939.png

Trying to set the arguments in the task:

User485076_1-1715869316567.png

the full thing is: -ExecutionPolicy Bypass -File "C:\Test\aTest.ps1" -ComputerName $(arg0) -UserName $(arg1)

 

The powershell script runs but doesn't set the variables in the script. Any ideas?

 

 

 

 

 

0 REPLIES 0