Set-Location "C:\" write-Host "Créations de la structure des dossiers..." -ForegroundColor Cyan $Folders = Import-Csv "C:\Users\Administrateur\Desktop\Scripts\folder_structure.csv" ForEach ($Folder in $Folders) { if (Test-Path -Path $Folder.Name) { write-Host "Le dossier existe déjà !" -ForegroundColor Red } else { New-Item $Folder.Name -type directory write-Host "Création du dossier $Folder" -ForegroundColor Green } echo "-------" echo 'Dossier :' $Folder.Name write-Host "Supression de l'heritage" -ForegroundColor Cyan $acl = Get-ACL -Path $Folder.Name $acl.SetAccessRuleProtection($True, $True) Set-Acl -Path $Folder.Name -AclObject $acl write-Host "OK!" -ForegroundColor Green write-Host "Supression des utilisateurs non-désirés" -ForegroundColor Cyan $acl = Get-ACL -Path $Folder.Name icacls C:\entreprise /remove 'CREATEUR PROPRIETAIRE' /t $usersid = New-Object System.Security.Principal.Ntaccount ("BUILTIN\Utilisateurs") $acl.PurgeAccessRules($usersid) $acl | Set-Acl -Path $Folder.Name write-Host "OK!" -ForegroundColor Green write-Host "Ajouter les ACL sur les dossiers" -ForegroundColor Cyan echo $Folder.Group echo $Folder.ACL $acl = Get-Acl -Path $Folder.Name $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($Folder.Group,$Folder.ACL,"Allow") $acl.SetAccessRule($AccessRule) $acl | Set-Acl -Path $Folder.Name write-Host "OK!" -ForegroundColor Green }