# encoding: ascii
# api: powershell
# title: AD_bulk_new_OU
# description: Active Directory, bulk create OU’s with defined sub OU’s
# version: 0.1
# type: script
# author: chriskenis
# license: CC0
# x-poshcode-id: 6346
# x-archived: 2016-05-19T19:59:35
# x-published: 2016-05-17T08:31:00
#
#
param(
$searchBase = "OU=Organisation,DC=uza,DC=local",
$NewOUs = @(Import-csv -Path "d:\projects\AD\departments.csv" -Delimiter ";"),
$SubOUs = @("Computers","Users"),
[switch]$ProtectOU
)
$Protect = $false
If ($ProtectOU){$Protect = $true}
foreach ($NewOU in $NewOUs){
New-ADOrganizationalUnit -Name $NewOU.name -Description $NewOU.description -City "Antwerp" -Country "BE" -ManagedBy $NewOU.manager -State "Antwerp" -Path $searchBase -ProtectedFromAccidentalDeletion $Protect
$SubOUPath = "OU=" + $Newou.Name + "," + $searchBase
foreach ($SubOU in $SubOUs){
New-ADOrganizationalUnit -Name $SubOU -Path $SubOUPath -ProtectedFromAccidentalDeletion $Protect
}
}
#example of CSV:
# headers => Name;description;manager
# datarow => accounting;ACC;TommyLee
# datarow => human resources;HRM;WendyRatzig