# Liste des groupes à créer
$GGServices = @(
"GG-Secrétaires",
"GG-Commerciaux",
"GG-Comptabilite",
"GG-Direction",
"GG-Informatique",
"GG-RH",
"GG-Stagiaires"
)
$GGUsine = @(
"GG-Stagiaires",
"GG-ProdAM",
"GG-ProdPM"
)
# Chemin de l'unité organisationnelle où les groupes seront créés
$OU_GG01 = "OU=Utilisateurs,OU=Service"
$OU_GG02 = "OU=Utilisateurs,OU=Usine"
$DCPath = "DC=vincent,DC=msprsx,DC=eni"
Function AddGroupAD {
param(
[string[]]$GG_Group,
[string]$OU_GGxx,
[string]$DCPath,
[string]$VarGroupScope,
[string]$VarGroupCategory
)
$OU_DC = "$OU_GGxx" + "," + "$DCPath"
foreach ($groupe in $GG_Group) {
# Vérifie si le groupe existe déjà
if (-not (Get-ADGroup -Filter "Name -eq '$groupe'")) {
# Crée le groupe s'il n'existe pas
New-ADGroup -Name $groupe -GroupScope $VarGroupScope -Path $OU_DC -GroupCategory $VarGroupCategory
Write-Output "Groupe de sécurité $groupe créé."
} else {
Write-Warning "Le groupe $groupe existe déjà."
}
}
}
## GroupScope = "DomainLocal" or "Universal" or "Global"
## GroupCategory = "Security" or "Distribution"
AddGroupAD -GG_Group $GGServices -OU_GGxx $OU_GG01 -DCPath $DCPath -VarGroupScope Global -VarGroupCategory Security
AddGroupAD -GG_Group $GGServices -OU_GGxx $OU_GG01 -DCPath $DCPath -VarGroupScope Global -VarGroupCategory Security
Start-Sleep 3