0 votes

Good afternoon everyone,
I have a web form that will create a simple OU with nothing more than a name and description. There next lies a business rule that kicks off a powershell script to generate some additional OU's underneath the one created by the form. Every once in a while the script will be ran against a different domain controller than the domain controller that processed the form create of the original OU.

At this point the script errors out because the root OU that it is creating additional OU's from does not exist because it has not replicated to the other DC.

How can I make sure my script is being ran from the same domain controller that the web interface ran its creation from?

by (360 points)

1 Answer

0 votes
by (216k points)
selected by
Best answer

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.

0

Thank for you for the code snippet. I will use that to get up and running in the short term and shift everything over to the ADSI edit in due time.

Much appreciated, thank you again!!!

Related questions

0 votes
1 answer

In Web Configuration, under advanced section we have set the Iddle Sessiom time out limit to 20 minutes and also the Authentication idle time out limit to 20 minutes, however ... there is any other way we can enforce re-login after session times out ? Thanks

asked Feb 13, 2021 by rsaran (70 points)
0 votes
1 answer

Hi Is it possible to get the Web Interface address via a script? Thanks Matt

asked Oct 13, 2023 by chappers77 (2.0k points)
0 votes
1 answer

Is it possible to grant selected user option to add custom license plan (or just subset of its licenses) to given user(s) using web interface?

asked Feb 28, 2023 by KIT (960 points)
0 votes
1 answer

I have Search configured for one of our web interfaces. One of the fields that can be searched is a custom attribute admCustomAttributeText4 (with a friendly name of ... are definitely some accounts with that attribute populated. Is this behaving as designed?

asked Sep 19, 2018 by sandramnc (870 points)
0 votes
1 answer

I have some custom command like "User Separation", which is sequenced with bunch of other actions, like disable, delete &amp; modify etc. This custom command is published ... time execution. And job executes on the particular date and time. Is the possible?

asked Sep 11, 2015 by Brajesh (460 points)
3,550 questions
3,241 answers
8,236 comments
547,827 users