Hello,
You can use the following code to get the DC used by Adaxes for a domain:
$domainName = $Context.GetObjectDomain("<Object_DN>")
$rootDSE = $Context.BindToObject("Adaxes://$domainName/rootDSE")
$domainControllerFQDN = $rootDSE.Get("dnsHostName")
# The $domainControllerFQDN variable contains the DNS host name
# of the DC used by Adaxes for the domain of the object
In the code above, <Object_DN> contains the Distinguished Name (DN) of the AD object for which you want to get the DC for. To get the DC used for the domain of the object on which your Business Rule is executed, specify the %distinguishedName% value reference.
You can pass the DC name you get to Adaxes cmdlets and to cmdlets from the ActiveDirectory PowerShell module using the -Server parameter, for example:
New-AdmOrganizationalUnit -Name "New Organizational Unit" -Path "%distinguishedName%" -Description "My New Organizational Unit" -Server $domainControllerFQDN
Also, consider using Adaxes ADSI interfaces for working with AD objects. Adaxes ADSI always performs the changes via Adaxes Service, which means that you don't need to care about which DC you are connected to. It will always be the DC used by Adaxes Service.
How to use the ADSI API to create an OU under the Organizational Unit on which a rule is executed:
$ou = $Context.TargetObject.Create("organizationalUnit", "OU=New Organizational Unit")
$ou.Put("description", "My New Organizational Unit")
$ou.SetInfo()
For details, see Creating Organizational Units.