Today is: 10 March, 2010

Adding rights to a file or folder with PowerShell

Pretty straight forward example and reference for adding rights to a folder or file with PowerShell.

Example

$AccessControl = get-acl "D:\My Documents"

$AccessRule = New-Object Security.AccessControl.FileSystemAccessRule("Users", "FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")

$AccessControl.AddAccessRule($AccessRule) set-acl -aclobject

$AccessControl -path "D:\My Documents"

Reference

Construction of FileSystemAccessRule object

FileSystemAccessRule(identity, fileSystemRights, inheritanceFlags, propagationFlags, type)

Inheritance and Propagation Translations

Subfolders and Files only
InheritanceFlags.ContainerInherit, InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly
This Folder, Subfolders and Files
InheritanceFlags.ContainerInherit, InheritanceFlags.ObjectInherit, PropagationFlags.None
This Folder, Subfolders and Files
InheritanceFlags.ContainerInherit, InheritanceFlags.ObjectInherit, PropagationFlags.NoPropagateInherit
This folder and subfolders
InheritanceFlags.ContainerInherit, PropagationFlags.None
Subfolders only
InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly
This folder and files
InheritanceFlags.ObjectInherit, PropagationFlags.None
This folder and files

InheritanceFlags.ObjectInherit, PropagationFlags.NoPropagateInherit