42 lines
952 B
PowerShell
42 lines
952 B
PowerShell
<#
|
|
|
|
#>
|
|
|
|
cls
|
|
|
|
#throw "This is not a robus script"
|
|
$location = Get-Location
|
|
Set-Location C:\Tools
|
|
|
|
Import-Module ActiveDirectory
|
|
|
|
$Fichier = "OU-Standard.csv"
|
|
|
|
$OUs = Import-Csv -Path $Fichier -Delimiter ";"
|
|
$dNC = (Get-ADRootDSE).defaultNamingContext
|
|
|
|
$OUs | ForEach-Object {
|
|
$name = $_.Name
|
|
$parentOU = $_.ParentOU
|
|
$Description = $_.Description
|
|
|
|
If ($ParentOU -eq '') {
|
|
$ouPath = "$dNC"
|
|
$testOUpath = "OU=$name,$dNC"
|
|
}
|
|
Else {
|
|
$ouPath = "OU=$parentOU,$dNC"
|
|
$testOUPath = "OU=$name,OU=$parentOU,$dNC"
|
|
}
|
|
|
|
$OUTest = (Get-ADOrganizationalUnit -Filter 'DistinguishedName -like $testOUpath' | Measure-Object).Count
|
|
|
|
If ($OUtest -eq 0) {
|
|
Write-host "Creation nouvelle OU '$testOUPath'"
|
|
New-ADOrganizationalUnit $name -Path $OUPath -ProtectedFromAccidentalDeletion:$false -Description $Description
|
|
}
|
|
Else {
|
|
Write-host "OU '$name' existe deja '$ouPath'"
|
|
}
|
|
}
|