---
title: "OU Management with Nodinite LDAP Web API: Complete Operations Guide with XML Examples"
description: Complete guide to Organizational Unit operations with the Nodinite LDAP Web API. Covers Select, Create, Update, Delete, Rename, and MoveTo with XML examples.
---

# OU Management with the Nodinite LDAP Web API

Comprehensive Organizational Unit (OU) management operations for LDAP directories using the <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [LDAP Web API][Overview]. This page covers all 6 OU-specific operations with detailed XML examples.

✅ **CRUD Operations**: Select, Create, Update, Delete OUs  
✅ **Reorganization**: Rename and Move OUs within directory structure  
✅ **Hierarchy Management**: Create nested OU structures programmatically  
✅ **Batch Support**: Process multiple OUs in single operations  
✅ **Flexible Queries**: Use searchFilter for precise OU targeting  

## Understanding OU Operations

OrganizationalUnit operations are available in the `Operations` section of the `OrganizationalUnit` record within the request message. Every operation uses the `With` record to define search criteria and scope; the LDAP Web API first finds the matching OUs, then runs each operation on them. Because an OU is a container, `Delete` and `MoveTo` also affect every object inside it.

<div class="mermaid">
flowchart LR
    Client["fa:fa-code Client"] -->|"Execute request (XML or JSON)"| API["fa:fa-cloud LDAP Web API"]
    API -->|"With: OU, DC, searchScope, searchFilter"| Dir["fa:fa-address-book LDAP directory"]
    Dir -->|"Matching OUs"| API
    API -->|"Operations on each matched OU and its children"| Dir
    API -->|"SearchResult and OperationResult"| Client
</div>

*Diagram: the LDAP Web API resolves the `With` query against the directory, then runs the OU operations on every OU found and returns both results.*

Both XML and JSON formats are supported. See the [Request Schema][Request] for message structure details.

---

## Operations Summary

|Operation|Description|Multiple Records|  
|---|---|---|  
|[Select](#select)|Retrieve OU records from LDAP|✅ Yes|  
|[Create](#create)|Create new OU with properties|❌ No|  
|[Update](#update)|Update existing OU properties|✅ Yes|  
|[Delete](#delete)|Delete OU and all children|✅ Yes|  
|[Rename](#rename)|Rename OU (OU name part)|❌ No|  
|[MoveTo](#moveto)|Move OUs to different location|✅ Yes|  

## Select

The `Select` operation retrieves OrganizationalUnit objects from the LDAP catalog using the search criteria provided in the `With` record.

### Example: Select OUs by Name Filter

```xml
<ns0:LDAP xmlns:ns0="http://integrationsoftware.se/BizTalk/Adapters/LDAP/Request/1.0">
  <Batches guid="67A6C24E-4282-4C87-AAE9-344C871531E9" returnResponseMessageOnExceptions="true">
    <Batch guid="2B25B9E6-4AF2-4094-9AE7-E1E4C99B6C8D">
      <OrganizationalUnit>
        <With DC="DC=ibiz,DC=local" searchScope="Subtree" expectedMatchCount="*" 
searchFilter="(name=Old*)"/>
        <Operations>
          <Select/>
        </Operations>
      </OrganizationalUnit>
    </Batch>
  </Batches>
</ns0:LDAP>
```

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p>Use <code>searchScope="Subtree"</code> to search recursively down the directory tree.</p></div>
</aside>

## Create

The `Create` operation creates a new OrganizationalUnit within the location found using the `With` record search criteria.

### Attributes

|Attribute|Required|Description|  
|---|---|---|  
|`name`|✅ Yes|The name of the OU to create|  
|`allowUpdateIfExists`|❌ No|Updates the existing OU with the properties collection content if the OU already exists. When `false` (default), the operation fails if the OU already exists|  

### Properties Element

The name-value pair collection with attributes for the OU object to be set by the operation.

### Example: Create a Nested OU

```xml
<ns0:LDAP xmlns:ns0="http://integrationsoftware.se/BizTalk/Adapters/LDAP/Request/1.0">
  <Batches guid="50CAC759-345A-479A-98AF-95B9FB515C8A" returnResponseMessageOnExceptions="true">
    <Batch guid="2B25B9E6-4AF2-4094-9AE7-E1E4C99B6C8D">      
      <OrganizationalUnit>
          <With OU="OU=Old hackers" DC="DC=ibiz,DC=local" searchScope="Base" 
expectedMatchCount="1"/>
          <Operations>
            <Create name="3l1t hackers3" allowUpdateIfExists="true">
              <Properties>
                <Property name="description" value="secret society."/>
              </Properties>
            </Create>
          </Operations>
        </OrganizationalUnit>
    </Batch>    
  </Batches>
</ns0:LDAP>
```

<aside aria-label="Note" class="nodinite-note nodinite-note--note">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-note"></i> Note</p>
<div class="nodinite-note__content"><p>The <code>allowUpdateIfExists</code> flag enables idempotent OU creation - useful for automated provisioning scripts.</p></div>
</aside>

## Update

The `Update` operation modifies existing OU properties for one or multiple OUs returned by the query.

### Properties Element

The attributes to be updated are provided in the name-value properties collection.

### Example: Update OU Description

```xml
<ns0:LDAP xmlns:ns0="http://integrationsoftware.se/BizTalk/Adapters/LDAP/Request/1.0">
  <Batches guid="50CAC759-345A-479A-98AF-95B9FB515C8A" returnResponseMessageOnExceptions="true">
    <Batch guid="2B25B9E6-4AF2-4094-9AE7-E1E4C99B6C8D">      
      <OrganizationalUnit>
          <With OU="OU=Old hackers" DC="DC=ibiz,DC=local" searchScope="Base" 
expectedMatchCount="1"/>
          <Operations>
            <Update>
              <Properties>
                <Property name="description" value="Other secret society."/>
              </Properties>
            </Update>
          </Operations>
        </OrganizationalUnit>
    </Batch>    
  </Batches>
</ns0:LDAP>
```

<aside aria-label="Note" class="nodinite-note nodinite-note--note">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-note"></i> Note</p>
<div class="nodinite-note__content"><p>The response shows data before and after the operation for verification.</p></div>
</aside>

## Delete

The `Delete` operation removes the OU and **all its children** from the LDAP catalog.

<aside aria-label="Warning" class="nodinite-note nodinite-note--warning">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-triangle-exclamation"></i> Warning</p>
<div class="nodinite-note__content"><p><i class="fal fa-exclamation-triangle" aria-hidden="true"></i> <strong>EXTREMELY DANGEROUS OPERATION</strong> <i class="fal fa-exclamation-triangle" aria-hidden="true"></i></p><p>The Delete operation <strong>recursively removes the OU and ALL child objects</strong> including:</p><ul>
<li><i class="fal fa-users" aria-hidden="true"></i> <strong>All users</strong> in the OU and nested OUs</li>
<li><i class="fal fa-user-group" aria-hidden="true"></i> <strong>All groups</strong> in the OU and nested OUs</li>
<li><i class="fal fa-folder-tree" aria-hidden="true"></i> <strong>All nested OUs</strong> and their entire contents</li>
</ul><p>This can <strong>permanently wipe entire branches of your Active Directory structure</strong> if search criteria are too broad.</p><p><strong>ALWAYS use <code>expectedMatchCount</code> attribute</strong> to specify the exact number of OUs you intend to delete. This safety check prevents accidental mass deletions. Follow these safety recommendations:</p><ul>
<li><i class="fal fa-shield-halved" aria-hidden="true"></i> <strong>Use <code>expectedMatchCount="1"</code></strong> - For single OU deletions, always set to exactly 1</li>
<li><i class="fal fa-magnifying-glass" aria-hidden="true"></i> <strong>Test with Select first</strong> - Run identical <code>With</code> criteria using <code>Select</code> operation to verify what will be deleted</li>
<li><i class="fal fa-vial" aria-hidden="true"></i> <strong>Test in non-production</strong> - Always test Delete operations in development/test environments first</li>
<li><i class="fal fa-filter" aria-hidden="true"></i> <strong>Use <code>searchScope="Base"</code></strong> - Never use <code>searchScope="Subtree"</code> for OU deletions unless you fully understand the consequences</li>
<li><i class="fal fa-list-check" aria-hidden="true"></i> <strong>Document OU contents</strong> - Use Select operation with <code>searchScope="Subtree"</code> to inventory all child objects before deletion</li>
<li><i class="fal fa-database" aria-hidden="true"></i> <strong>Backup before bulk deletes</strong> - Ensure Active Directory backups are current and tested before any OU deletion</li>
<li><i class="fal fa-user-lock" aria-hidden="true"></i> <strong>Restrict permissions</strong> - Limit LDAP Web API service account permissions to specific OUs where deletions are allowed</li>
</ul><p>See <a href="https://docs.nodinite.com/ldap-web-api/features/request/">Request Schema - expectedMatchCount</a> for detailed attribute documentation.</p></div>
</aside>

### Example: Delete a Specific OU

```xml
<ns0:LDAP xmlns:ns0="http://integrationsoftware.se/BizTalk/Adapters/LDAP/Request/1.0">
  <Batches guid="EC117D12-3B90-42C0-AF52-B1501623A637" returnResponseMessageOnExceptions="true">
    <Batch guid="2B25B9E6-4AF2-4094-9AE7-E1E4C99B6C8D">
      <OrganizationalUnit>
          <With OU="OU=happy hackers,OU=Old hackers" DC="DC=ibiz,DC=local" searchScope="Base" 
expectedMatchCount="1"/>
          <Operations>
            <Delete/>
          </Operations>
        </OrganizationalUnit>
    </Batch>    
  </Batches>
</ns0:LDAP>
```

The response `SearchResult` displays the OU found for deletion, and the operation result confirms deletion with details about removed objects.

## Rename

The `Rename` operation changes the name of an OU. The target name must not already exist, or the operation fails.

### Attributes

|Attribute|Required|Description|  
|---|---|---|  
|`name`|✅ Yes|The new name for the OU object|  

<aside aria-label="Warning" class="nodinite-note nodinite-note--warning">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-triangle-exclamation"></i> Warning</p>
<div class="nodinite-note__content"><p>The target name must be unique. If an OU with the new name already exists, the operation fails.</p></div>
</aside>

### Example: Rename an OU

```xml
<ns0:LDAP xmlns:ns0="http://integrationsoftware.se/BizTalk/Adapters/LDAP/Request/1.0">
  <Batches guid="E9DAB4D9-757B-4C2A-9372-93C2F80F3EA0" returnResponseMessageOnExceptions="true">
    <Batch guid="2B25B9E6-4AF2-4094-9AE7-E1E4C99B6C8D">
      <OrganizationalUnit>
        <With OU="OU=3l1t hackers,OU=Old hackers" DC="DC=ibiz,DC=local" searchScope="Base" 
expectedMatchCount="1"/>
        <Operations>
          <Rename name="3l1t hackers2"/>
        </Operations>
      </OrganizationalUnit>
    </Batch>
  </Batches>
</ns0:LDAP>
```

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p>The response displays the OU with data before and after the update. Use <code>returnProperties</code> to limit the number of attributes returned.</p></div>
</aside>

## MoveTo

The `MoveTo` operation moves OUs found by the `With` search criteria to the destination location specified in the operation arguments.

### Attributes

|Attribute|Required|Description|  
|---|---|---|  
|`DC`|✅ Yes|Domain Component for the destination|  
|`OU`|✅ Yes|Organizational Unit path for the destination|  
|`CN`|❌ No|Common Name for the destination (rarely used for OU moves)|  

<aside aria-label="Note" class="nodinite-note nodinite-note--note">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-note"></i> Note</p>
<div class="nodinite-note__content"><p>Multiple records are supported in a single request. For example, you can move all OUs beginning with 'A*' from anywhere in the tree to a specific destination.</p></div>
</aside>

### Example: Move an OU

```xml
<ns0:LDAP xmlns:ns0="http://integrationsoftware.se/BizTalk/Adapters/LDAP/Request/1.0">
  <Batches guid="2B25B9E6-4AF2-4094-9AE7-E1E4C99B6C8E">
    <Batch transactionScopeOption="Required" continueOnError="false" 
guid="2B25B9E6-4AF2-4094-9AE7-E1E4C99B6C8D">
      <OrganizationalUnit>
        <With OU="OU=happy customers,OU=Old hackers" DC="DC=ibiz,DC=local" searchScope="Base" 
expectedMatchCount="1"/>
        <Operations>
          <MoveTo OU="OU=3l1t hackers2,OU=Old hackers" DC="DC=ibiz,DC=local"/>
        </Operations>
      </OrganizationalUnit>
    </Batch>
  </Batches>
</ns0:LDAP>
```

<aside aria-label="Note" class="nodinite-note nodinite-note--note">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-note"></i> Note</p>
<div class="nodinite-note__content"><p>When moving an OU, all child objects (users, groups, nested OUs) move with it, maintaining the hierarchy.</p></div>
</aside>

## Common Use Cases

### Directory Restructuring

Use `MoveTo` and `Rename` operations to reorganize your directory structure without recreating objects or breaking references.

### Automated Provisioning

Combine `Create` with `allowUpdateIfExists` to build idempotent provisioning scripts that can be safely re-executed.

### Cleanup & Decommissioning

Use `Select` with `searchFilter` to identify OUs matching specific patterns, then `Delete` to remove obsolete organizational structures.

### Multi-Tenant Management

Create hierarchical OU structures for each tenant or department, then use `Select` to query tenant-specific information.

### Disaster Recovery

Query existing OU structures with `Select`, document the hierarchy, and use `Create` to rebuild structures in recovery scenarios.

---

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* Review the [Request Schema][Request] for complete message structure  
* Explore the [Response Schema][Response] for understanding operation results  
* Learn about [User Management][User Management] for populating OUs with users  
* Learn about [Group Management][Group Management] for OU-based group organization  
* Check [Logging][Logging] for troubleshooting and auditing  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* [LDAP Web API Overview][Overview]  
* [AD Management][AD Management]  
* [Schema Management][Schema Management]  

[AD Management]:https://docs.nodinite.com/ldap-web-api/features/ad-management/
[Group Management]:https://docs.nodinite.com/ldap-web-api/features/group-management/
[Logging]:https://docs.nodinite.com/ldap-web-api/troubleshooting/logging/
[Overview]:https://docs.nodinite.com/ldap-web-api/overview/
[Request]:https://docs.nodinite.com/ldap-web-api/features/request/
[Response]:https://docs.nodinite.com/ldap-web-api/features/response/
[Schema Management]:https://docs.nodinite.com/ldap-web-api/features/schema-management/
[User Management]:https://docs.nodinite.com/ldap-web-api/features/user-management/