Custom Powershell Activity - Passing Variables

Steven Parker
Giga Sage

So I am just testing a new custom PowerShell activity.  This works fine and does exactly what I would expect in a test:

find_real_file.png

However, when I add this to a script file, I can't figure out how to pass my ${activityInput.groupName} variable to the $Server variable in the PowerShell script.  Here is the script I added to the Midserver:

find_real_file.png

How do I pass my ${activityInput.groupName} into the Powershell script file?

I tried changing my Midserver script to this:

find_real_file.png

and then updating my Powershell custom activity to this:

find_real_file.png

But that also didn't work....

Any help here?


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
1 ACCEPTED SOLUTION

Steven Parker
Giga Sage

For anyone trying to do this in the future, we found 2 different ways to do it...both easy:

Solution 1:

Point to the PS1 file and then pass the variable ($Server was the variable in our Example).  In our example, we were just outputting a text file on the midserver so our target host was the midserver itself.  I had to check "Use MID Service Account" because of creating the text file on itself when running.

find_real_file.png

 

Solution 2:

Go to MID Server -> Script Files and create a new Script there.  Below is the screenshot of the script you would then point to in your custom Powershell activity.  The custom Powershell activity "Script Type" would then become a "MID Server Script File" (then choose your script you created) and the "Server" variable in my example would now be "Servername" because of Servername being my variable in the below screenshot.

find_real_file.png

 

These are just examples of how to pass variables to a custom PS1 file or a Script File created within ServiceNow in the MID Server application.


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

View solution in original post

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

Below should help you

 

https://community.servicenow.com/community?id=community_article&sys_id=6801f040dbfbdf00feb1a851ca9619f3

 

Regards,

Sachin

That seems complicated...

Is there any benefit to using a MID Server Script file over a Customer PowerShell Command in my custom activity?  I can do what I want in a Custom PowerShell Command, but was just trying to test out using a MID Server Script file.


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

Steven Parker
Giga Sage

For anyone trying to do this in the future, we found 2 different ways to do it...both easy:

Solution 1:

Point to the PS1 file and then pass the variable ($Server was the variable in our Example).  In our example, we were just outputting a text file on the midserver so our target host was the midserver itself.  I had to check "Use MID Service Account" because of creating the text file on itself when running.

find_real_file.png

 

Solution 2:

Go to MID Server -> Script Files and create a new Script there.  Below is the screenshot of the script you would then point to in your custom Powershell activity.  The custom Powershell activity "Script Type" would then become a "MID Server Script File" (then choose your script you created) and the "Server" variable in my example would now be "Servername" because of Servername being my variable in the below screenshot.

find_real_file.png

 

These are just examples of how to pass variables to a custom PS1 file or a Script File created within ServiceNow in the MID Server application.


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

can you please share the PowerShell Script?

Thanks,

Imane