0 votes

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 the best way of doing this? I tried modifying the Items on the AdmCustomCommandParameterCheckList of the Adaxes Customer Command (AdmContainerPipelined) in question but it won't let me modify it. I could use reflection, or other tricks, but I think I'm probably doing this the wrong way.

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

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

# Bind to the custom commands container.
$containerPath = $service.Backend.GetConfigurationContainerPath( "CustomCommands")
$container = $service.OpenObject($containerPath, $null, $null, 0)

# Get command
$command = $container | Where-Object { $_.CommandName -eq 'My Custom Command' } | Select-Object -First 1
for($parameterIndex=0; $parameterIndex -lt $command.Parameters.Count; $parameterIndex++) {
    if($command.Parameters[$parameterIndex] -is [Softerra.Adaxes.Parameters.AdmParameterCheckList]) {
        break;
    }
}
if($parameterIndex -ge $command.Parameters.Count) {
    throw "Didn't find Parameter"
}

# Example Items
$Items = @{
    "1" = "One"
    "2" = "Two"
    "3" = "Three"
}

$ItemsList = @()
foreach($Key in $Items.Keys) {
    Write-Host $Key
    $Item = [Softerra.Adaxes.Parameters.AdmParameterCheck]::new()
    $Item.ValueWhenChecked = $Key
    $Item.Name = "param-{$((New-Guid).ToString().ToUpper())}"
    $Item.DisplayName = $Items[$Key]
    $ItemsList += [Softerra.Adaxes.Interop.Adsi.Parameters.IAdmParameterCheck]$Item
    #$command.Parameters[$parameterIndex].Items.Add($Item) # fixed length array, won't work
}
$command.Parameters[$parameterIndex].Items = [Softerra.Adaxes.Interop.Adsi.Parameters.IAdmParameterCheck[]]$ItemsList # Also doesn't work
$command.SetInfo()
by (210 points)

1 Answer

0 votes
by (272k points)

Hello,

Going via UI is definitely much easier. However, if you prefer using scripts, the following SDK article should be helpful: https://www.adaxes.com/sdk/IAdmParameterCheckList. Pay attention that each item has a setting for value when checked and when unchecked. If you still face issues writing the script, please, describe the desired behavior in all the possible details with live examples.

0

But how do I save the created instance to an existing parameter on the command?

0

Hello,

Have a look at section Adding parameters to a custom command of the following SDK article: https://www.adaxes.com/sdk/ManagingCustomCommands/#adding-parameters-to-a-custom-command.

Related questions

0 votes
1 answer

Is it possible to populate Custom Command Drop-Down List and Checkbox List items using PowerShell? If not, is such a feature on the Adaxes roadmap?

asked Dec 12, 2022 by Viajaz (210 points)
0 votes
1 answer

I used the script below to try and accomplish this but I get an error. I did try to leave a comment but it would not let me. I tried running ... .adaxes.com/script-repository/add-users-located-in-particular-organizational-units-to-unmanaged-accounts-s178.htm

asked Nov 14, 2022 by raul.ramirez (210 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)
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 (2.3k points)
0 votes
1 answer

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. ... , $NULL, $NULL, 0) $obj.ExecuteCustomCommand($command.CommandID, $commandArguments) Thanks in advance!

asked Nov 24, 2021 by KelseaIT (320 points)
3,351 questions
3,052 answers
7,791 comments
545,088 users