Mise en place de drapeaux de transmission et de Propagation avec set-acl et powershell

j'essaie d'imiter l'action de droit-cliquer sur un dossier, mettre "modifier" sur un dossier, et avoir les permissions s'appliquent au dossier spécifique et aux sous-dossiers et fichiers.

je suis la plupart du temps là en utilisant Powershell, cependant l'héritage est seulement défini comme "sous-dossiers et fichiers" au lieu de l'ensemble "ce dossier, sous-dossiers et fichiers".

y a-t-il un drapeau non inscrit pour le système?Sécurité.AccessControl.PropagationFlags qui définira ceci correctement?

voici avec quoi je travaille jusqu'à présent.

$Folders = Get-childItem c:TEMP
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::InheritOnly
$objType = [System.Security.AccessControl.AccessControlType]::Allow 

foreach ($TempFolder in $Folders)
{
echo "Loop Iteration"
$Folder = $TempFolder.FullName

$acl = Get-Acl $Folder
$permission = "domainuser","Modify", $InheritanceFlag, $PropagationFlag, $objType
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission

$acl.SetAccessRule($accessRule)
Set-Acl $Folder $acl
} 
38
demandé sur Frank Schwieterman 2010-07-19 19:48:16

5 réponses

je pense que votre réponse peut être trouvée sur cette page. À partir de la page:

ce dossier, sous-dossiers et fichiers:

InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit 
PropagationFlags.None
26
répondu David Gladfelter 2010-07-20 07:56:22

Voici une table pour vous aider à trouver les options nécessaires pour différentes combinaisons de permission.

    ╔═════════════╦═════════════╦═══════════════════════════════╦════════════════════════╦══════════════════╦═══════════════════════╦═════════════╦═════════════╗
    ║             ║ folder only ║ folder, sub-folders and files ║ folder and sub-folders ║ folder and files ║ sub-folders and files ║ sub-folders ║    files    ║
    ╠═════════════╬═════════════╬═══════════════════════════════╬════════════════════════╬══════════════════╬═══════════════════════╬═════════════╬═════════════╣
    ║ Propagation ║ none        ║ none                          ║ none                   ║ none             ║ InheritOnly           ║ InheritOnly ║ InheritOnly ║
    ║ Inheritance ║ none        ║ Container|Object              ║ Container              ║ Object           ║ Container|Object      ║ Container   ║ Object      ║
    ╚═════════════╩═════════════╩═══════════════════════════════╩════════════════════════╩══════════════════╩═══════════════════════╩═════════════╩═════════════╝

donc, comme David l'a dit, vous voudrez

    InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit 
    PropagationFlags.None
    
57
répondu Nick Sarabyn 2011-12-05 18:49:08

ce N'est pas parce que tu es à PowerShell que tu oublies les bons vieux ex. Parfois, ils peuvent fournir la solution la plus facile, par exemple:

icacls.exe $folder /grant 'domain\user:(OI)(CI)(M)'
8
répondu Keith Hill 2010-07-19 17:07:17

voici un bref code Powershell pour appliquer de nouvelles permissions à un dossier en modifiant sa liste de contrôle D'accès (ACL).

# Get the ACL for an existing folder
$existingAcl = Get-Acl -Path 'C:\DemoFolder'

# Set the permissions that you want to apply to the folder
$permissions = $env:username, 'Read,Modify', 'ContainerInherit,ObjectInherit', 'None', 'Allow'

# Create a new FileSystemAccessRule object
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permissions

# Modify the existing ACL to include the new rule
$existingAcl.SetAccessRule($rule)

# Apply the modified access rule to the folder
$existingAcl | Set-Acl -Path 'C:\DemoFolder'

chacune des valeurs de $permissions la liste des variables se rapporte aux paramètres de constructeur pour les FileSystemAccessRule classe.

gracieuseté de cette page.

5
répondu Luke 2017-05-25 08:27:26

Voici the MSDN page décrivant les drapeaux et le résultat de leurs différentes combinaisons.

Flag combinations => Propagation results
=========================================
No Flags => Target folder.
ObjectInherit => Target folder, child object (file), grandchild object (file).
ObjectInherit and NoPropagateInherit => Target folder, child object (file).
ObjectInherit and InheritOnly => Child object (file), grandchild object (file).
ObjectInherit, InheritOnly, and NoPropagateInherit => Child object (file).
ContainerInherit => Target folder, child folder, grandchild folder.
ContainerInherit, and NoPropagateInherit => Target folder, child folder.
ContainerInherit, and InheritOnly => Child folder, grandchild folder.
ContainerInherit, InheritOnly, and NoPropagateInherit => Child folder.
ContainerInherit, and ObjectInherit => Target folder, child folder, child object (file), grandchild folder, grandchild object (file).
ContainerInherit, ObjectInherit, and NoPropagateInherit => Target folder, child folder, child object (file).
ContainerInherit, ObjectInherit, and InheritOnly => Child folder, child object (file), grandchild folder, grandchild object (file).
ContainerInherit, ObjectInherit, NoPropagateInherit, InheritOnly => Child folder, child object (file).

pour qu'il applique les permissions au répertoire, ainsi que tous les répertoires et fichiers enfants de façon récursive, vous devrez utiliser ces options:

InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit 
PropagationFlags.None

donc le changement de code spécifique que vous devez faire pour votre exemple est:

$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
1
répondu deadlydog 2016-11-04 21:18:09