0 votes

Is it possible to update a Propery Pattern using a powershell script? If a new department OU is created, is it possible to automaticly update the User Pattern's Department property to reflect that a new department has been added?

by (960 points)
0

Yes, this is possible. To implement the script for you, we need to know how do you identify that a newly created OU is a department OU. Do you create all your department OUs under a certain OU? Or is there some other way that we can identify that the new OU is a department OU?

Also, you can take a look at Managing Property Patterns in our SDK (see Example 1: Mark the Department property as required and provide a list of possible values for the property).

0

All OU's created directly under the OU "Departments" should be specified in list of possible selections for the property Depatment.

It should just add the new OU to the existing list.

I took a look at the SDK for Managing Property Patterns, but i could not figure out how to just add a new selection, without deleting the existing list of selections.

1 Answer

0 votes
by (960 points)
edited by

We figured out how to script this:

[Reflection.Assembly\]::LoadWithPartialName("Softerra.Adaxes.Adsi")  

$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"  
$admService = $admNS.GetServiceDirectly("localhost")  

$propertyPatternsPath = $admService.Backend.GetConfigurationContainerPath(  
 "PropertyPatterns")  
$propertyPatternsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `  
 $propertyPatternsPath  
$builtinPathObj = $propertyPatternsPathObj.CreateChildPath("CN=Builtin")  
$userPatternPath = $builtinPathObj.CreateChildPath("CN=User Pattern")  

$userPattern = $admService.OpenObject($userPatternPath.ToString(),  
 $NULL, $NULL, 0)  
foreach ($item in $userPattern.Items)  
{  
 if ($item.PropertyName -ieq "Department")  
 {  
 $constraints = $item.GetConstraints()   
 $constraint = $constraints.GetConstraint("ADM\_PROPERTYCONSTRAINTCATEGORY\_VALUEFORMAT")  
 $constraint.Values += "%ou%"  
 $item.SetConstraints($constraints)   
 $item.SetInfo()   
 break   
 }  
}
0

Hello,

There is one small issue with your version of the script. The thing is that it adds a new department to the list of departments when a new OU is created, but if an OU is deleted, your version of the script will not update the Property Pattern. We suggest a bit different approach.

You can create two Business Rules, one of which will be triggered after creating an OU, the other one will be triggered after deleting an OU. Both the Business Rules will launch a Custom Command that will run a PowerShell script. The script will update the list of departments based on the names of OUs under the Departments OU. Running script from a Custom Command (and not directly in the Business Rules) will allow you to keep the script in a single place. If you need to modify the script in the future, you will need to update only the Custom Command. Also, you can create a Scheduled Task that will run periodically and and launch the same Custom Command to update the list of departments. This is useful if some OUs will be created or deleted outside of Adaxes. To implement this functionality:

I. Create the Custom Command that will launch the script

  1. Create a new Custom Command.

  2. On the 1st step of the Create Custom Command wizard, you can disable the Custom Command. Disabled Custom Commands are not visible for users in the UI and cannot be executed manually, but can be executed from Business Rules, Custom Commands or Scheduled Tasks. To disable the Custom Command, uncheck the Enabled option.

  3. On the 2nd step, select the Organizational-Unit object type.

  4. On the 3rd step, add the Run a program or PowerShell script action and paste the following script:

     # Get a list of department names
     $Context.TargetObject.Filter = @("organizationalUnit")
     $departmentNames = @()
     foreach ($department in $Context.TargetObject)
     {
         $departmentNames += $department.Get("name")
     }
    
     if ($departmentNames.Length -eq 0)
     {
         return
     }    
    
     # Build the ADS path of the built-in Property Pattern called 'User Pattern'
     $propertyPatternsPath = $Context.GetWellKnownContainerPath("PropertyPatterns")
     $propertyPatternsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $propertyPatternsPath
     $builtinPathObj = $propertyPatternsPathObj.CreateChildPath("CN=Builtin")
     $patternPath = $builtinPathObj.CreateChildPath("CN=User Pattern")
    
     # Bind to the Property Pattern
     $pattern = $Context.BindToObject($patternPath)
    
     # Delete the item for the 'Department' property
     foreach ($item in $pattern.Items)
     {
         if ($item.PropertyName -ieq "department")
         {
             $pattern.Items.Remove($item)
             break
         }
     }
    
     # Create a new item for the 'Department' property
     $item = $pattern.Items.Create()
     $item.PropertyName = "department"
     $item.IsPropertyRequired = $False # Set to $True to make the 'Department' property required
    
     $constraints = $item.GetConstraints()
     $constraint = $constraints.Create("ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
     $constraint.AreValuesDenied = $False
     $constraint.Values = $departmentNames
     $constraints.Add($constraint)
     $item.SetConstraints($constraints)
    
     # Save the changes
     $item.SetInfo()
     $pattern.Items.Add($item)
    
  5. Add a short description for the script and click OK.

  6. Finish creation of the Custom Command.

II. Create Business Rules to update the list of departments after creating or deleting a department OU

  1. Create a new Business Rule.

  2. On the 2nd step:

    • for the Business Rule that will be executed after creating an OU, select Organizational-Unit and After Creating an Organizational-Unit;
    • for the Business Rule that will be executed after deleting an OU, select Organizational-Unit and After Deleting an Organizational-Unit.
  3. On the 3rd step, add the Execute a Custom Command action and click Select.

  4. In the dialog box that appears, select the Custom Command that you created on step I.

  5. Click OK two times.

  6. On the 4th step, assign the Business Rule over your Departments OU and specify the Child objects of this Organizational-Unit and Immediate child objects only in the Assignment Options dialog.

  7. Finish creation of the Business Rule.

III. Create a Scheduled Task to update the list of departments on schedule

  1. Create a new Scheduled Task.
  2. On the 3rd step, select the Organizational-Unit object type.
  3. On the 4th step, add the Execute a Custom Command action and click Select.
  4. In the dialog box that appears, select the Custom Command that you created on step I.
  5. Click OK two times.
  6. On the 4th step, assign theScheduled Task over your Departments OU and specify the Child objects of this Organizational-Unit and Immediate child objects only in the Assignment Options dialog.
  7. Finish creation of the Scheduled Task.

Related questions

0 votes
1 answer

When we create a shared mailbox, we create an associated mail-enabled security group. In the security group I want to populate the description field with the name of the shared mailbox ... How can I get just the "name" of the shared mailbox versus the full DN?

asked Feb 4, 2021 by atnorman (120 points)
0 votes
1 answer

Hello, I have trouble understanding the instruction listed here: https://www.adaxes.com/script-repositor ... s-s516.htm What should I put into $propertyForSearch and ... Since Adaxes is not the only system adding new locations to AD. Thank you.

asked Jul 4, 2019 by DLe (760 points)
0 votes
1 answer

I am trying to use a property pattern to prevent email forwarding to accounts in other domains managed by Adaxes. Here is my regex: ^([^,]+,)+(DC=domain,DC=local) ... 't working? Is Adaxes using some other value before resolving the DN? Thanks in advance! Leah

asked May 9, 2019 by loliver (120 points)
0 votes
1 answer

Hi I need to update some property patterns on a scheduled basis and am doing this via a powershell script. The particular attibute will be a drop down, but ... t work! $item.SetConstraints($constraints) $item.SetInfo() $userPattern.Items.Add($item) Thanks Matt

asked Nov 11, 2020 by chappers77 (2.0k points)
0 votes
1 answer

Good afternoon, I'm looking to generate a script to allow automation of updating job titles using a spreadsheet. To do this we would use a spreadsheet generated by ... in calling the file. Please let me know if you require any additional information Regards

asked Nov 16, 2020 by jtop (680 points)
3,347 questions
3,048 answers
7,787 comments
545,035 users