Get identifier of Adaxes configuration object

Each Adaxes configuration object (e.g. custom command, report, business unit) has an immutable identifier that doesn't change even after the configuration backup/restore. These identifiers can be used to locate and refer to specific configuration objects in your scripts. For example, to execute a custom command in a script, you need to know the command identifier, which can be obtained using one of the methods below.

Get identifier by object name

To search for a configuration object by name and get its identifier, use the following script.

In the script:

  • $serviceHost – the host name of the computer where the Adaxes service is installed.
  • $objectNameToSearch – the name of the configuration object to search for.

$objectNameToSearch can contain wildcards (* character) to get the identifiers of multiple objects or search for objects whose name you're unsure of. For example:

  • Specify My* to get the identifiers of all objects whose names start with My.
  • Specify * to get the identifiers of all configuration objects.
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

$serviceHost = "localhost"
$objectNameToSearch = "My object*"

# Prompt for credentials.
$credential = Get-Credential

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

# Search objects
$configRootPath = $service.Backend.GetConfigurationContainerPath("ConfigurationRoot")
$searcher = $service.OpenObject($configRootPath, 
    $credential.UserName, $credential.GetNetworkCredential().Password, 0)
$searcher.Criteria = New-AdmCriteria `
    -Type "adm-CustomCommand","adm-BusinessRule","adm-BusinessUnit",`
    "adm-PropertyPattern","adm-Report","adm-ReportOverview" `
    -Expression {name -eq $objectNameToSearch}
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    
try
{
    # Execute search
    $searchResultIterator = $searcher.ExecuteSearch()
    $searchResults = $searchResultIterator.FetchAll()
    
    if ($searchResults.Length -gt 0)
    {
        foreach ($searchResult in $searchResults)
        {
            if ($searchResult.ObjectType -eq "objectClass=adm-CustomCommand")
            {
                $id = [Guid]$searchResult.Properties["adm-CustomCommandID"].Value
            }
            else
            {
                $id = [Guid]$searchResult.Properties["adm-ObjectID"].Value
            }

            # Output information
            Write-Host "`nName:" $searchResult.Properties["name"].Value
            Write-Host "ID:" $id
            Write-Host "Type:" $searchResult.ObjectType
            Write-Host "DN:" $searchResult.Properties["distinguishedName"].Value
        }
    }
    else
    {
        Write-Host "`nNo objects found."
    }
}
finally
{
    # Release resources
    if ($searchResultIterator){ $searchResultIterator.Dispose() }
}

Get identifier by DN

If you know the distinguished name of the configuration object, you can get its identifier using the following script.

In the script:

  • $serviceHost – the host name of the computer where the Adaxes service is installed.
  • $objDN – the distinguished name of an Adaxes configuration object. For details on how to get the DN of a configuration object, see Get the DN of a directory object.
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

$serviceHost = "localhost" 
$objDN = "CN=My Command,CN=Custom Commands,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes"

# Prompt for credentials.
$credential = Get-Credential

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

# Bind to the configuration object.
$configObject = $service.OpenObject("Adaxes://$objDN", $credential.UserName, `
    $credential.GetNetworkCredential().Password, 0)

# Get object identifier.
if ($configObject.Class -ne "adm-CustomCommand")
{
    $id = [Guid]$configObject.Get("adm-ObjectId")
}
else
{
    $id = [Guid]$configObject.Get("adm-CustomCommandId")
}

Write-Host "ID: $id"

See also