Code is below. But the subject says it all. When I run the command targeted in this function via the Adaxes GUI or the web interface, it runs without issue. When run using this code, I just get "No operations executed" in the log. When checking the Adaxes log, the information in the log is exactly the same as when I run the command successfully via the GUI.
function create-PltAccount {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
$identity,
[string] $commandGuid = "9D8EF2CC-21D8-4843-9FFE-F21E7FE356E4",
[Parameter(Mandatory = $true)]
[ValidateSet("user","sa","da")]
[string] $accountType,
[Alias("domain","server")]
[string] $managedDomain = "domain.com",
[string] $adaxesService = $global:adaxesService,
[Alias("saCred")]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$credential
)
begin {
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi") > $null
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$credUser = $credential.UserName
$credPwd = $credential.GetNetworkCredential().Password
$admService = $admNS.GetServiceDirectly($adaxesService)
}
process {
try {
$objectDn = $identity.DistinguishedName
$objectName = $identity.Name
write-host "Adaxes://$managedDomain/$objectDn"
$adaxesObject = $admNS.OpenObject($adaxesService,"Adaxes://$managedDomain/$objectDn", $credUser, $credPwd, 195)
$command = $admNS.OpenObject($adaxesService,"Adaxes://<GUID=$commandGuid>", $credUser, $credPwd, 195)
switch ($accountType) {
"user" { $paramAccountType = "Domain Account"; break }
"sa" { $paramAccountType = "SA Account"; break }
"da" { $paramAccountType = "DA Account"; break }
}
$arguments = $command.CreateArguments()
$arguments.SetParameterValue("param-AccountType", $paramAccountType)
if ($psCmdlet.ShouldProcess($objectName, "Run 'PLT - Create-PLT-DomainAccount' against user '$($identity.name)' creating '$paramAccountType' account")) {
write-progress "Waiting for command to complete..."
$adaxesObject.ExecuteCustomCommand($command.CommandId, $arguments)
#retrieve status
sleep -sec 15 #sleep to allow log entry to show up
$logRecord = $adaxesObject.getModificationLog().log.getPage(0) | select -first 1
if (($logRecord.State -ne 4) -or ($logRecord.state -ne "OPERATION_STATE_COMPLETED")) {
write-warning "$commandName failed on '$objectName'"
write-warning $logRecord.getExecutionLog().message
} else {
if ($logRecord.getExecutionLog().message) {
write-output $logRecord.getExecutionLog().message
}
}
write-progress "Waiting for command to complete..." -completed
}
} catch {
$psCmdlet.WriteError($_); return
} finally { $adaxesObject = $null }
}
end {
$admNS = $admService = $credUser = $credPwd = $null
}
}