0%
script PowerShell

script PowerShell

![image](https://github.com/user-attachments/assets/68b33865-69fb-45bd-a680-893726dd1c69)

10-15 min

script PowerShell

image

# Import the Active Directory module
Import-Module ActiveDirectory

# Define the root domain
$domain = "DC=test,DC=local"

# Create top-level OUs for Quebec and Ontario
New-ADOrganizationalUnit -Name "Quebec" -Path $domain
New-ADOrganizationalUnit -Name "Ontario" -Path $domain

# Create sub-OUs for departments under Quebec
New-ADOrganizationalUnit -Name "RH" -Path "OU=Quebec,$domain"
New-ADOrganizationalUnit -Name "Informatique" -Path "OU=Quebec,$domain"
New-ADOrganizationalUnit -Name "Marketing" -Path "OU=Informatique,OU=Quebec,$domain"

# Create sub-OUs for departments under Ontario
New-ADOrganizationalUnit -Name "Informatique" -Path "OU=Ontario,$domain"
New-ADOrganizationalUnit -Name "Marketing" -Path "OU=Ontario,$domain"

# Create groups for each department in Quebec and Ontario
New-ADGroup -Name "RH-QC" -GroupScope Global -GroupCategory Security -Path "OU=RH,OU=Quebec,$domain"
New-ADGroup -Name "Info-QC" -GroupScope Global -GroupCategory Security -Path "OU=Informatique,OU=Quebec,$domain"
New-ADGroup -Name "Marketing-QC" -GroupScope Global -GroupCategory Security -Path "OU=Marketing,OU=Informatique,OU=Quebec,$domain"

New-ADGroup -Name "Info-ON" -GroupScope Global -GroupCategory Security -Path "OU=Informatique,OU=Ontario,$domain"
New-ADGroup -Name "Marketing-ON" -GroupScope Global -GroupCategory Security -Path "OU=Marketing,OU=Ontario,$domain"
Lien copié !