PoshCode Archive  Artifact [567da5e12a]

Artifact 567da5e12a7a33e2b42467b4158a0e6286ee897fae2e841ded0910440e721250:

  • File AD_bulk_new_OU.ps1 — part of check-in [21473755db] at 2018-06-10 14:13:40 on branch trunk — Active Directory, bulk create OU’s with defined sub OU’s (user: chriskenis size: 1132)

# 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