# Hiérarchie des GDL

[![agdlp.png](https://docs.rakouns.bzh/uploads/images/gallery/2025-10/scaled-1680-/HB5agdlp-png.png)](https://docs.rakouns.bzh/uploads/images/gallery/2025-10/scaled-1680-/HB5agdlp-png.png)

## Introduction

Nous reprenons une nouvelle fois notre fichier CSV :

[![image.png](https://docs.rakouns.bzh/uploads/images/gallery/2026-02/scaled-1680-/vDDimage.png)](https://docs.rakouns.bzh/uploads/images/gallery/2026-02/vDDimage.png)

```
NIVEAU 1;NIVEAU 2;NIVEAU 3;NIVEAU 4;NIVEAU 5;NIVEAU 6;NIVEAU 7;NIVEAU 8;FolderPath;CREER_GROUPES;GG_ECRITURE;GG_LECTURE;GDL_ECRITURE;GDL_LECTURE;GDL_VUE;Parent_GDL
01-DIRECTION;;;;;;;;01-DIRECTION;;ORG_GG_DIRECTION;;GDL_01_ECRITURE;GDL_01_LECTURE;GDL_01_VUE;
02-FINANCE;;;;;;;;02-FINANCE;;ORG_GG_FINANCE;ORG_GG_DIRECTION;GDL_02_ECRITURE;GDL_02_LECTURE;GDL_02_VUE;
02-FINANCE;01-BUDGET;;;;;;;02-FINANCE\01-BUDGET;;ORG_GG_FINANCE;ORG_GG_DIRECTION;GDL_02-01_ECRITURE;GDL_02-01_LECTURE;GDL_02-01_VUE;GDL_02_VUE
02-FINANCE;02-FACTURES;;;;;;;02-FINANCE\02-FACTURES;;ORG_GG_FINANCE;ORG_GG_DIRECTION;GDL_02-02_ECRITURE;GDL_02-02_LECTURE;GDL_02-02_VUE;GDL_02_VUE
03-RH;;;;;;;;03-RH;;ORG_GG_RH;ORG_GG_DIRECTION;GDL_03_ECRITURE;GDL_03_LECTURE;GDL_03_VUE;
03-RH;01-CONTRATS;;;;;;;03-RH\01-CONTRATS;;ORG_GG_RH;ORG_GG_DIRECTION;GDL_03-01_ECRITURE;GDL_03-01_LECTURE;GDL_03-01_VUE;GDL_03_VUE
03-RH;02-PAIE;;;;;;;03-RH;NON;;;;;;
04-IT;;;;;;;;04-IT;;ORG_GG_IT;ORG_GG_DIRECTION;GDL_04_ECRITURE;GDL_04_LECTURE;GDL_04_VUE;
04-IT;01-INFRA;;;;;;;04-IT\01-INFRA;;ORG_GG_IT;ORG_GG_DIRECTION;GDL_04-01_ECRITURE;GDL_04-01_LECTURE;GDL_04-01_VUE;GDL_04_VUE
04-IT;02-PROJETS;;;;;;;04-IT\02-PROJETS;;ORG_GG_IT;ORG_GG_DIRECTION;GDL_04-02_ECRITURE;GDL_04-02_LECTURE;GDL_04-02_VUE;GDL_04_VUE
04-IT;02-PROJETS;2026;;;;;;04-IT\02-PROJETS\2026;NON;;;;;;
```

Ici, il faut que le GDL "04-IT\\02-PROJETS" qui est lecture ou écriture donc "**GDL\_04-02\_ECRITURE**" ou "**GDL\_04-02\_LECTURE** soient membre de "04-IT" vue donc "**GDL\_04\_VUE**" etc etc

De plus, il faut, au contraire que "**GDL\_01\_ECRITURE**"ou "**GDL\_04-02\_LECTURE**" par exemple aient des droits récursifs sur l'ensemble des enfants, mais cela sera pour une prochaine partie.

## Mise en place de la hiérarchie

On en vient donc au script qui permet de faire ça.  
Il va simplement lire les colonnes GDL\_ECRITURE, GDL\_LECTURE, GDL\_VUE et Parent\_GDL, ce qui lui donnes toutes les infos nécessaires :

```powershell
<#
===============================================================================
SCRIPT : 3.1 - Creation_Parentalite.ps1
OBJET  : Chainer les GDL de chaque dossier vers le GDL_VUE de leur parent
===============================================================================

DESCRIPTION :
  - Pour chaque ligne du CSV :
        * Si Parent_GDL est renseigne :
             - Ajouter GDL_ECRITURE   -> Parent_GDL
             - Ajouter GDL_LECTURE    -> Parent_GDL
             - Ajouter GDL_VUE        -> Parent_GDL
  - Tous les messages visibles sont sans accents.
  - Commentaires en francais pour clarifier chaque etape.

NOTE :
  - Ce script n effectue PAS de creation de groupes.
    Il se contente de realiser le chainage entre niveaux.
  - Fonctionne sur les noms de groupes crees dans le script 2.1.

===============================================================================
#>

Param(
    [string]$CsvPath = "C:\AGDLP\ORG_ARBO_GDL.csv"
)

$ErrorActionPreference = "Stop"

# ----------------------------------------------------------------------------
# Module ActiveDirectory
# ----------------------------------------------------------------------------
try {
    Import-Module ActiveDirectory -ErrorAction Stop
}
catch {
    Write-Error "Module ActiveDirectory introuvable. Installer RSAT AD PowerShell."
    exit 1
}

# ----------------------------------------------------------------------------
# Lecture du CSV
# ----------------------------------------------------------------------------
if (-not (Test-Path $CsvPath)) {
    Write-Error "CSV introuvable : $CsvPath"
    exit 1
}

$rows  = Import-Csv -Path $CsvPath -Delimiter ";" -Encoding UTF8
$total = $rows.Count
$index = 0

Write-Host "Application de la parentalite GDL a partir du fichier : $CsvPath"
Write-Host ""

# ----------------------------------------------------------------------------
# Boucle principale
# ----------------------------------------------------------------------------
foreach ($row in $rows) {
    $index++

    # Mettre a jour la progression
    Write-Progress -Activity "Chainage GDL enfant -> Parent_GDL" `
                   -Status "$index / $total" `
                   -PercentComplete (($index/$total)*100)

    # Recuperation du parent
    $parent = $row.Parent_GDL
    if ([string]::IsNullOrWhiteSpace($parent)) {
        # Aucun parent pour cette ligne
        continue
    }

    # Verifier que le parent existe dans l AD
    $parentGroup = Get-ADGroup -Filter "Name -eq '$parent'" -ErrorAction SilentlyContinue
    if (-not $parentGroup) {
        Write-Warning "Parent GDL introuvable dans AD : $parent"
        continue
    }

    # Groupes enfants a chainer
    $childGroups = @()

    if ($row.GDL_ECRITURE -and $row.GDL_ECRITURE.Trim() -ne "") {
        $childGroups += $row.GDL_ECRITURE.Trim()
    }
    if ($row.GDL_LECTURE -and $row.GDL_LECTURE.Trim() -ne "") {
        $childGroups += $row.GDL_LECTURE.Trim()
    }
    if ($row.GDL_VUE -and $row.GDL_VUE.Trim() -ne "") {
        $childGroups += $row.GDL_VUE.Trim()
    }

    # Ajouter les groupes enfants dans le groupe parent
    foreach ($cg in $childGroups) {

        $exists = Get-ADGroup -Filter "Name -eq '$cg'" -ErrorAction SilentlyContinue
        if (-not $exists) {
            Write-Warning "GDL enfant introuvable : $cg"
            continue
        }

        try {
            Add-ADGroupMember -Identity $parent -Members $cg -ErrorAction Stop
            Write-Host "Chaine : $cg -> $parent"
        }
        catch {
            Write-Warning "Erreur chainage : $cg -> $parent   ($_ )"
        }
    }
}

# Effacer la barre de progression
Write-Progress -Activity "Chainage GDL enfant -> Parent_GDL" -Completed

Write-Host ""
Write-Host "Chainage parental GDL termine." -ForegroundColor Green
```

Avec cela, chaque enfant VUE, LECTURE et ECRITURE est membre de son parent VUE direct.  
Prochaine étape appliquer les ACL aux répertoires du partage !