# encoding: ascii
# api: powershell
# title: AD_bulk_new_OU
# description: JEFFTEST
# version: 0.1
# type: script
# author: jeff3
# license: CC0
# x-poshcode-id: 6232
# x-derived-from-id: 6233
# x-archived: 2016-08-26T03:54:35
# x-published: 2016-02-24T21:59:00
#
# test2
#
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
