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 (170 points)

1 Answer

0 votes
by (211k points)
selected ago 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 by Constey (170 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

I would like to add a parameter for country to a custom command. Since the country has to be entered correctly in order for Active Directory to accept it, I would like to ... ? I didn't find it in the documentation and the sample scripts didn't use parameters.

asked Jun 4, 2020 by mark.it.admin (1.7k points)
0 votes
1 answer

Is it possible to use Property Patterns for Parameters in custom commands? I would like to be able to restrict certain characters that users are inputting, especially since some of these parameters are used for logon names etc. Thanks

asked Aug 19, 2020 by bavery (230 points)
2,607 questions
2,344 answers
6,228 comments
860,949 users