Windows 2019
Sponsored Link

Active Directory : Add Organizational Unit(CUI)
2019/02/25
 
Add Organizational Unit with Commands on CUI.
[1] Run PowerShell or Command Prompt and use [dsadd ou] command.
The command does not have an option to enable [Protect container from accidental deletion], but if you'd like to enable it, Use PowerShell Cmdlet (refer to the [3] section).
# show current Organizational Unit list
PS C:\Users\Administrator> dsquery ou -name * 
"OU=Domain Controllers,DC=srv,DC=world"

# for example, add an Organizational Unit [Hiroshima]
PS C:\Users\Administrator> dsadd ou OU=Hiroshima,DC=srv,DC=world 
dsadd succeeded:OU=Hiroshima,DC=srv,DC=world

PS C:\Users\Administrator> dsquery ou -name Hiroshima 
"OU=Hiroshima,DC=srv,DC=world"

# for adding OU under the existing OU, specifu the Path like follows
# add an OU [Development01] under the OU [Hiroshima]
PS C:\Users\Administrator> dsadd ou OU=Development01,OU=Hiroshima,DC=srv,DC=world 
dsadd succeeded:OU=Development01,OU=Hiroshima,DC=srv,DC=world


# options for [dsadd ou]
PS C:\Users\Administrator> dsadd ou /? 

Description:  Adds an organizational unit to the directory

Syntax:  dsadd ou <OrganizationalUnitDN> [-desc <Description>]
        [{-s <Server> | -d <Domain>}] [-u <UserName>]
        [-p {<Password> | *}] [-q] [{-uc | -uco | -uci}]

.....
.....
[2] If you'd like to delete Organizational Units, use [dsrm] command.
This command is based on the case the option [Protect container from accidental deletion] is not enabled for Organizational Unit, if enabled, Use PowerShell Cmdlet (refer to the [3] section).
# for example, delete an OU [Development01]
PS C:\Users\Administrator> dsquery ou -name Development01 
"OU=Development01,OU=Hiroshima,DC=srv,DC=world"

PS C:\Users\Administrator> dsrm "OU=Development01,OU=Hiroshima,DC=srv,DC=world" 
Are you sure you wish to delete OU=Development01,OU=Hiroshima,DC=srv,DC=world (Y/N)? y
dsrm succeeded:OU=Development01,OU=Hiroshima,DC=srv,DC=world
[3] If you use PowerShell, It's possible to use Cmdlet for PowerShell.
# show current Organizational Unit list
PS C:\Users\Administrator> Get-ADOrganizationalUnit -Filter * | Format-Table DistinguishedName 

DistinguishedName
-----------------
OU=Domain Controllers,DC=srv,DC=world
OU=Hiroshima,DC=srv,DC=world

# for example, add [Development01] under the [Hiroshima]
PS C:\Users\Administrator> New-ADOrganizationalUnit Development01 `
-Path "OU=Hiroshima,DC=srv,DC=world" `
-ProtectedFromAccidentalDeletion $True 

# verify
PS C:\Users\Administrator> Get-ADOrganizationalUnit -Filter * | Format-Table DistinguishedName 

DistinguishedName
-----------------
OU=Domain Controllers,DC=srv,DC=world
OU=Hiroshima,DC=srv,DC=world
OU=Development01,OU=Hiroshima,DC=srv,DC=world


# if the option [ProtectedFromAccidentalDeletion] is enabled,
# disable it first and delete it
PS C:\Users\Administrator> Set-ADOrganizationalUnit `
-Identity "OU=Development01,OU=Hiroshima,DC=srv,DC=world" `
-ProtectedFromAccidentalDeletion $false 

PS C:\Users\Administrator> Remove-ADOrganizationalUnit -Identity "OU=Development01,OU=Hiroshima,DC=srv,DC=world" 

Confirm
Are you sure you want to perform this action?
Performing the operation "Remove" on target "OU=Development01,OU=Hiroshima,DC=srv,DC=world".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y


# options for [New-ADOrganizationalUnit]
PS C:\Users\Administrator> Get-Help New-ADOrganizationalUnit 

NAME
    New-ADOrganizationalUnit

SYNOPSIS
    Creates a new Active Directory organizational unit.


SYNTAX
    New-ADOrganizationalUnit [-Name] <String> [-AuthType {Negotiate | Basic}] [-City <String>] [-Country <String>] [-Cr
    edential <PSCredential>] [-Description <String>] [-DisplayName <String>] [-Instance <ADOrganizationalUnit>] [-Manag
    edBy <ADPrincipal>] [-OtherAttributes <Hashtable>] [-PassThru] [-Path <String>] [-PostalCode <String>] [-ProtectedF
    romAccidentalDeletion <Boolean>] [-Server <String>] [-State <String>] [-StreetAddress <String>] [-Confirm] [-WhatIf
    ] [<CommonParameters>]

.....
.....
Matched Content