$MyLine = [string] $PathToProcess = [string] $PathFolderForCACLS = [string] $CheminFichier = [string] $AdministratorLogin = [string] $AdministratorLogin = "Administrators" $PathToProcess = "C:\Chemin à traiter" $NomFichier = "BatCACLS.bat" $RepertoireFichier = "C:\Repertoire pour ecrire le BAT resultant" $CheminFichier = "$RepertoireFichier\$NomFichier" Write-Host $CheminFichier $MonFichier = New-Item -type file $CheminFichier -Force $MonFolder = Get-ChildItem -Path $PathToProcess | Where-Object {$_.PSIsContainer} foreach ($MySubFolder in $MonFolder) { $PathFolderForCACLS = "`""+$PathToProcess+"\"+$MySubFolder.name+"`"" $MyLine = "TAKEOWN /F $PathFolderForCACLS /a /r /d Y" add-content $MonFichier $MyLine $MyLine = "iCACLS $PathFolderForCACLS /reset /T /C /Q" add-content $MonFichier $MyLine $MyLine = "iCACLS $PathFolderForCACLS /Grant `""+$MySubFolder.name+"`":(OI)(CI)F /C /Q" add-content $MonFichier $MyLine $MyLine = "iCACLS $PathFolderForCACLS /setowner `""+$MySubFolder.name+"`" /T /C /Q" add-content $MonFichier $MyLine }