Passing an array into a powershell activity

huntj06
Tera Guru

I'm looking for the syntax on how to pass an array of users to add to an ad group using the powershell activity.

I've created an input called "userList" with a type of "Array". I've got a for loop in my powershell command line:

Import-Module "C:\Program Files\Dell\Active Roles\7.0\Shell\ActiveRolesManagementShell"

$groupMember = "${activityInput.groupName}"

$memberName = "${activityInput.userList}"

ForEach ($User in $memberName)

{

add-QADGroupMember $groupMember -Service 'wprnedifars004v'   -Member $User —proxy -credential $cred

}

Am I going about this wrong. Any pointers?

4 REPLIES 4

CPKIII
Tera Expert

OK.   Maybe how I conquered this will help.   First things first formatting the array correctly as it is transferred into Powershell is key.   Her is a sample of my script that sets the workflow.scratchpad.  



var sysidpa = current.variables.prod_admins.toString();


//admins


admins = "";


var nmpa = sysidpa.split(",");


for(i=0;i < nmpa.length;i++){


  if(i < nmpa.length - 1){


admins = admins + '"' + findUser(nmpa[i]) + '",';


  }


  else


  admins = admins + '"' + findUser(nmpa[i]) + '"';


}



What is in bold is the key, it sets the formatting correctly with leading and ending " , because you not will set those when you declare the variable in power-shell like below.  



$admins = ${workflow.scratchpad.admins}




Once you get the scratchpad variable set to look like this:       "username1", "username2", "username3"    



you can change your powershell variable to



$memberName = ${activityInput.userList}



Then do this for your loop:



if($memberName){


foreach($user in $memberName){


$groupMember | ADD-ADGroupMember   —members $user


}


}



Hope this helps.


I'm trying "test inputs" on the form, and it's still not working.



I'm passing this in my test inputs:


userList: "DOMAIN\User.Name","DOMAIN\Bob.Name"


groupName: Group Name



Command Script:


Import-Module "C:\Program Files\Dell\Active Roles\7.0\Shell\ActiveRolesManagementShell"


$groupMember = "${activityInput.groupName}"


$memberName = "${activityInput.userList}"




foreach($User in $memberName)


{


add-QADGroupMember $groupMember -Service 'wprnedifars004v'   -Member $User —proxy -credential $cred


}



and I'm gettting the error message



t C:\Users\XXXXXXXXXX\AppData\Local\Temp\script.5189381063753832946.PS1:3 char:17+ $memberName = ""DOMAIN\User.Name","DOMAIN\Name.Bob""+                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Unexpected token 'DOMAIN\User.Name","DOMAIN\Name.Bob""' in expression or statement.Stack Trace


I've attached the powershell activity screen shot here.


I just figured out, I must remove the quotes in the "command" activity for it to accept the array.