Files
Scripts-Pack-Epsic-122/insert_OUs.ps1

23 lines
848 B
PowerShell

# Nom du script : insert_OUs.ps1
Import-Module ActiveDirectory
$csvPath = "happy_koalas_employees.csv"
$domainDN = (Get-ADDomain).DistinguishedName
Write-Host "--- Création des Unités d'Organisation (OU) ---" -ForegroundColor Cyan
# Lecture du CSV
$employees = Import-Csv -Path $csvPath -Delimiter ";"
# On récupère la liste unique des départements
$departments = $employees | Select-Object -ExpandProperty Department -Unique
foreach ($dept in $departments) {
# On vérifie si l'OU existe déjà pour éviter les erreurs rouges
if (-not (Get-ADOrganizationalUnit -Filter "Name -eq '$dept'")) {
New-ADOrganizationalUnit -Name $dept -Path $domainDN
Write-Host "[OK] OU créée : $dept" -ForegroundColor Green
} else {
Write-Host "[INFO] L'OU $dept existe déjà." -ForegroundColor Yellow
}
}