Manage Organizational Units Using Active Directory PowerShell

Continuing with my Active Directory PowerShell Module series today I’ll show you how to manage Organizational Units using the Active Directory PowerShell Module.

This article follows the previous article where I showed how to use the PowerShell Module to Copy Group Membership From One User To Another.

The first example I’ll show will create a new OU Inside the DEV OU:

New-ADOrganizationalUnit -Name "Servers" -Path 'OU=dev,DC=test,DC=local' -PassThru -Verbose

I can also create multiple Ous from a .CSV file as seen below:

Import-Csv .\ous.csv | foreach{New-ADOrganizationalUnit -Name $_.ou -Path 'OU=dev,DC=test,DC=local' -PassThru -Verbose }

To disable protect OU feature from newly created OU type:

New-ADOrganizationalUnit -Name "Web Servers" -Path 'OU=dev,DC=test,DC=local' -PassThru -Verbose -ProtectedFromAccidentalDeletion $false

I can so use an existing OU as a template to for creating a new OU:

$OuTemplate = Get-ADOrganizationalUnit -Identity 'OU=Exchange Servers,OU=dev,DC=test,DC=local'
New-ADOrganizationalUnit -Name "AV Servers" -Instance $OuTemplate -Path 'OU=dev,DC=test,DC=local'

To view all Ous In AD type:

Get-ADOrganizationalUnit -Filter * | Format-Table Name, DistinguishedName


Posted

in

by