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 (272k 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 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

I need to add many check-box list items to a Custom Command, I think the best way to do this is via PowerShell rather than through the UI. What's ... Softerra.Adaxes.Interop.Adsi.Parameters.IAdmParameterCheck[]]$ItemsList # Also doesn't work $command.SetInfo()

asked Jan 4 by Viajaz (210 points)
0 votes
1 answer

We have several scripts that use the following action: $commandID = "{b4b66610-be71-403a-a6b7-8bcf51d200ef}" $user.executecustomCommand($commandID) is there syntax that allows ... is there another way to pass parameters to a custom command through scripting?

asked Jul 11, 2019 by ggallaway (300 points)
0 votes
1 answer

Here is my issue, When I use this code: $DNs = %param-GroupsInRole% $Groups = $DNs -split "|" %Param-GroupsInRole% can have multiple groups. When setting up the parameter I am ... I just need to be able to do a foreach with the groups picked by the initiator.

asked Mar 23, 2023 by mightycabal (1.0k points)
3,346 questions
3,047 answers
7,782 comments
544,984 users