Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

MID Server Script Variables

Community Alums
Not applicable

Hello All,

i am having difficult time to understand how inputs in a power shell custom activity is getting passed to MID Server Script file; and how can we define a environment variable like i have seen in few OOB scripts, refer below - 

 

if (test-path env:\SNC_groupname) {
$groupname = $env:SNC_groupname;
$username = $env:SNC_username;
};

 

Regards, Bharat

3 REPLIES 3

Mike Patel
Tera Sage

Variables are passed in from Workflow activity.

find_real_file.png

Community Alums
Not applicable

Below is the MID Server script for AddUserToADGroup.ps1

 

import-module "$executingScriptDirectory\AD\ActiveDirectory"

if (test-path env:\SNC_groupname) {
$groupname = $env:SNC_groupname;
$username = $env:SNC_username;
};

SNCLog-ParameterInfo @("Running AddUserToADGroup", $groupname, $username)

addADUserAccountToGroup -domainController $computer -username $username -groupname $groupname -useCred $useCred -credential $cred

 

# here $computer,$userCred and $cred isnt defined; and how environment variables are defined ? 

Thanks in advance !

shwalala
Tera Contributor

you will pass them from the custom pack, if you are using a workflow.

 

shwalala_0-1675205806155.png

add groupname and username in the name column of the powershell variables. The same can be done with flow designer