This commit is contained in:
2023-11-28 17:36:11 +01:00
parent 92d8156af0
commit ad43503820
19 changed files with 316 additions and 195 deletions

42
Step-01-Creation-OU.ps1 Normal file
View File

@ -0,0 +1,42 @@
<#
#>
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'"
}
}