3 créer des OU (organization unit) avec powershell + fichier csv

Опубликовано: 01 Июль 2026
на канале: PC Aide
575
5

Les scripts + ...:

▲▲▲▲▲▲▲▲
►1_New-OU.ps1◄
▼▼▼▼▼▼▼▼
lien externe:
http://pastebin.com/r6XC3UmX

Pour télécharger:
https://drive.google.com/open?id=0B2_...

▲▲▲▲▲▲▲▲
►0_listOU.csv◄
▼▼▼▼▼▼▼▼
lien externe:
http://pastebin.com/cyxUZnF4

Pour télécharger:
https://drive.google.com/open?id=0B2_...

████████████████████████
█ Set-ExecutionPolicy unrestricted██

███████████
█0_New-OU.ps1█

#-----------------------------------------------------------------------
FileName : New-OU.ps1
Description : Powershell script creates OU into Active Directory from a CSV File.
Remarks : CSV file must contains Name and Path.
#
#-----------------------------------------------------------------------
param([parameter(Mandatory=$true)] [String]$FileCSV)
$listOU=Import-CSV $FileCSV -Delimiter ";"

ForEach($OU in $listOU){

try{
#Get Name and Path from the source file
$OUName = $OU.Name
$OUPath = $OU.Path

#Display the name and path of the new OU
Write-Host -Foregroundcolor Yellow $OUName $OUPath

#Create OU
New-ADOrganizationalUnit -Name "$OUName" -Path "$OUPath" -ProtectedFromAccidentalDeletion $false

#Display confirmation
Write-Host -ForegroundColor Green "OU $OUName created"
}catch{

Write-Host $error[0].Exception.Message
}

}
██████████
█0_listOU.csv█

name;path
EDUC-PLUSinc;"DC=dt3adrlsdml,DC=cours,DC=edu"
Quebec-OU;"OU=EDUC-PLUSinc,DC=dt3adrlsdml,DC=cours,DC=edu"
Ventes;"OU=Quebec-OU,OU=EDUC-PLUSinc,DC=dt3adrlsdml,DC=cours,DC=edu"
Math;"OU=Quebec-OU,OU=EDUC-PLUSinc,DC=dt3adrlsdml,DC=cours,DC=edu"
Direction;"OU=Quebec-OU,OU=EDUC-PLUSinc,DC=dt3adrlsdml,DC=cours,DC=edu"
Ressources humaines;"OU=Quebec-OU,OU=EDUC-PLUSinc,DC=dt3adrlsdml,DC=cours,DC=edu"
Informatique;"OU=Quebec-OU,OU=EDUC-PLUSinc,DC=dt3adrlsdml,DC=cours,DC=edu"
Programmation;"OU=Informatique,OU=Quebec-OU,OU=EDUC-PLUSinc,DC=dt3adrlsdml,DC=cours,DC=edu"
Reseautique;"OU=Informatique,OU=Quebec-OU,OU=EDUC-PLUSinc,DC=dt3adrlsdml,DC=cours,DC=edu"