0 votes

Hello,

I'm trying to execute a custom command through a Powershell script, but I'm struggling to pass multiple values to an AD Object Picker parameter. Is there a way to do that? I've tried passing it as an array of distinguished names, as a string with each one separated by semicolons (which matches the character used to separate them in the parameter configuration), and as a string with each one separated by new lines, but I get the errors "Input string was not in a correct format," or "DN was invalid." Here's my code if it helps:

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the custom command
$commandDN = "<distinguished name of the custom command>"
$command = $admService.OpenObject("Adaxes://$commandDN", $NULL, $NULL, 0)

# define parameter values
$groupName = "GroupName"
$owners    = "Owner1DistinguishedName", "Owner2DistinguishedName", "Owner3DistinguishedName"
$members   = "Member1DistinguishedName", "Member2DistinguishedName", "Member3DistinguishedName"

# Specify the arguments for command execution
$commandArguments = $command.CreateArguments()
$commandArguments.SetParameterValue("param-groupName", $groupName) # edit box parameter
$commandArguments.SetParameterValue("param-owners", $owners)       # AD object picker parameter
$commandArguments.SetParameterValue("param-members", $members)     # AD object picker parameter

# Run the custom command
$obj = $admService.OpenObject("Adaxes://<distinguished name of OU>", $NULL, $NULL, 0)
$obj.ExecuteCustomCommand($command.CommandID, $commandArguments)

Thanks in advance!

by (320 points)

1 Answer

0 votes
by (294k points)
selected by
Best answer

Hello,

It has to be an array containing distinguished names (DNs) of the objects. Also, your script misses the line for loading the assembly. Finally, it should look like the following:

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the custom command
$commandDN = "<distinguished name of the custom command>"
$command = $admService.OpenObject("Adaxes://$commandDN", $NULL, $NULL, 0)

# define parameter values
$groupName = "GroupName"
$owners = @("Owner1DistinguishedName", "Owner2DistinguishedName", "Owner3DistinguishedName")
$members = @("Member1DistinguishedName", "Member2DistinguishedName", "Member3DistinguishedName")

# Specify the arguments for command execution
$commandArguments = $command.CreateArguments()
$commandArguments.SetParameterValue("param-groupName", $groupName) # edit box parameter
$commandArguments.SetParameterValue("param-owners", $owners)       # AD object picker parameter
$commandArguments.SetParameterValue("param-members", $members)     # AD object picker parameter

# Run the custom command
$obj = $admService.OpenObject("Adaxes://<distinguished name of OU>", $NULL, $NULL, 0)
$obj.ExecuteCustomCommand($command.CommandID, $commandArguments)

If you get error messages using this approach, it means that there is something incorrect about working with the parameters in your custom command itself, not in the script executing the command. For example, if you need to add the target user to multiple groups selected in the parameter, the script in the custom command will look like below.

$separator = ";" # TODO: modify me

# Get parameter value
$parameterValue = $Context.GetParameterValue("param-owners")

# Add user to groups
foreach ($dn in $parameterValue.Split($separator))
{
    $group = $Context.BindToObjectByDN($dn)
    $group.Add($Context.TargetObject.AdsPath)
}

In the script, the $separator variable specifies the character used to separate object DNs in the parameter. It must match that specified in the parameter settings. image.png

0

That worked. I also had to fix an error in how I was handling the parameter in the custom command script. Thanks for you help!

Related questions

0 votes
1 answer

I have a number of custom Powershell scripts that add users to Teams, groups, etc. I re-use these scripts dozens of times for different conditions and only change one ... possible to convert this script to a custom command and pass parameters to it instead?

asked 6 days ago by cwyant-hfg (40 points)
0 votes
1 answer

We've the following script we want to use in Adaxes to create as part of user creation, to ask if the user will need a AWS workspace, then asks employeetype for different ... "Error") exit(-1) } else { $Context.LogMessage("Created workspace", "Information") }

asked May 3 by Plusa (20 points)
0 votes
1 answer

I had a business rules that had a PowerShell script to update User properties in a SQL table. It was working fine. I moved the PowerShell to a custom command so I could ... in the custom command does get the values for the User object. Am I missing something?

asked Jun 2, 2014 by sdavidson (730 points)
0 votes
1 answer

Hi there, i've a custom command with multiple powershell scripts (for clearance reasons). If for example the frist script produces an error i Write an Error but the next ... tried with an simple exit 1; I only Write-Errors on issues. Kind regards, Constantin

asked Jul 23, 2021 by Constey (190 points)
0 votes
1 answer

The use case we are looking for is providing a list of titles for users to choose from when initiating a re-hire. We already have a title property pattern established and would ... that we can manage the list in one place. Let me know and as always, thanks.

asked Nov 22 by msheppard (610 points)
3,588 questions
3,277 answers
8,303 comments
548,090 users