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