{"id":333,"date":"2022-10-20T01:49:32","date_gmt":"2022-10-20T01:49:32","guid":{"rendered":"https:\/\/merserver.com\/?p=333"},"modified":"2022-10-20T01:49:33","modified_gmt":"2022-10-20T01:49:33","slug":"changing-ntfs-security-permissions-using-powershell","status":"publish","type":"post","link":"http:\/\/merserver.com\/index.php\/2022\/10\/20\/changing-ntfs-security-permissions-using-powershell\/","title":{"rendered":"Changing NTFS Security Permissions using PowerShell"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\" id=\"overview\">Overview<\/h1>\n\n\n\n<p>Changing NTFS permissions with PowerShell saves a lot of time when you need to make changes to a large group of files or when it is required as part of a larger automation project. This article should help you understand everything you need to know to manipulate security permissions with PowerShell.<\/p>\n\n\n\n<p>When changing ownership of files or folders&nbsp;<em>you must<\/em>&nbsp;run PowerShell as an Administrator. Everything here will work in Windows PowerShell 5, but not PowerShell 6 as of this writing \u2013 specifically, the SetAccessControl() method does not exist in PowerShell 6.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"viewing-acl\">Viewing ACL<\/h1>\n\n\n\n<p>We are going to use the&nbsp;<code>Get-Acl<\/code>&nbsp;cmdlet to view the current ACL. Running it in PowerShell will give the following output.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>1 2 3 4 5 6 7 8 9 10 11<\/code><\/td><td><code><em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>Get-Acl<\/em> .\\Directory\\ | <em>Format-List<\/em> Path : Microsoft.PowerShell.Core\\FileSystem::C:\\Users\\Administrator\\Documents\\Directory\\ Owner : <em>WIN-UBFNHEQ8GII<\/em>\\Administrator <em>Group<\/em> : <em>WIN-UBFNHEQ8GII<\/em>\\None Access : NT AUTHORITY\\SYSTEM Allow FullControl BUILTIN\\Administrators Allow FullControl <em>WIN-UBFNHEQ8GII<\/em>\\Administrator Allow FullControl Audit : Sddl : O:LAG:S-1-5-21-3514988389-1168544693-1271638760-513D:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;LA)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Our primary focus in this article will be on the Owner and Access objects. We can see from this example that&nbsp;<code>WIN-UBFNHEQ8GII\\Administrator<\/code>&nbsp;is the owner and we have three Access rules granting FullControl.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ownership-details\">Ownership Details<\/h2>\n\n\n\n<p>Ownership is pretty simple. Ownership is assigned to one user or group and there are no additional details.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>1 2<\/code><\/td><td><code><em>PS <\/em>C:\\Users\\larntz\\Documents&gt; (<em>Get-Acl<\/em> .\\Directory\\).Owner <em>WIN-UBFNHEQ8GII<\/em>\\Administrator<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"access-right-details\">Access Right Details<\/h2>\n\n\n\n<p>We can see a more detailed description of the access rules by selecting them specifically using this command&nbsp;<code>(Get-Acl .\\Directory\\).Access<\/code>. Now we can see which permissions were inherited and the InheritanceFlags and PropagationFlags. These latter two will be important when we start modifying rules.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23<\/code><\/td><td><code><em>PS <\/em>C:\\Users\\larntz\\Documents&gt; (<em>Get-Acl<\/em> .\\Directory\\).Access FileSystemRights : FullControl AccessControlType : Allow IdentityReference : NT AUTHORITY\\SYSTEM IsInherited : True InheritanceFlags : ContainerInherit, ObjectInherit PropagationFlags : None FileSystemRights : FullControl AccessControlType : Allow IdentityReference : BUILTIN\\Administrators IsInherited : True InheritanceFlags : ContainerInherit, ObjectInherit PropagationFlags : None FileSystemRights : FullControl AccessControlType : Allow IdentityReference : <em>WIN-UBFNHEQ8GII<\/em>\\Administrator IsInherited : True InheritanceFlags : ContainerInherit, ObjectInherit PropagationFlags : None<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"modifying-acl\">Modifying ACL<\/h1>\n\n\n\n<p>Before we can set an object\u2019s ACL we need to build one. The easiest way to do that is to save the current ACL in a variable and then modify it. To do that we\u2019ll just assing the output of&nbsp;<code>Get-Acl<\/code>&nbsp;to&nbsp;<code>$acl<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>1<\/code><\/td><td><code><em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$acl<\/em> = <em>Get-Acl<\/em> .\\Directory\\<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Another option would be to create a completely new, and empty, ACL object like this:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>1<\/code><\/td><td><code><em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$acl<\/em> = <em>New-Object<\/em> System.Security.AccessControl.DirectorySecurity<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Now that we have our ACl object we can make modifications. Once we\u2019ve made the desired changes we&nbsp;<em>have to apply it back to the directory<\/em>&nbsp;or our changes will be lost.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"setting-ownership\">Setting Ownership<\/h2>\n\n\n\n<p>Setting the owner in the ACL is almost as simple as viewing it. We will use the&nbsp;<code>SetOwner()<\/code>&nbsp;method on the ACL. This method takes one argument of type&nbsp;<code>System.Security.Principal.NTAccount<\/code>&nbsp;so first we need to create an object of that type and then we can set the owner.<\/p>\n\n\n\n<p>However, there are two limitations when setting ownership via PowerShell.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>We need to be running powershell as Administrator.<\/li><li>We can only set the owner to the user currently running PowerShell or&nbsp;<code>BUILTIN\\Administrators<\/code>.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>1 2<\/code><\/td><td><code><em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$owner<\/em> = <em>New-Object<\/em> System.Security.Principal.NTAccount(\"BUILTIN\\Administrators\") <em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$acl<\/em>.SetOwner(<em>$owner<\/em>)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Remember, we haven\u2019t changed anything on the filesystem yet. We\u2019ve only modified our&nbsp;<code>$acl<\/code>&nbsp;object.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"inheritance-flags\">Inheritance Flags<\/h2>\n\n\n\n<p>When creating access rules we will want to specify inheritance flags also. When doing so we have four options. You will most likely want to set both the&nbsp;<code>ContainerInheritance<\/code>&nbsp;and the&nbsp;<code>ObjectInheritance<\/code>&nbsp;flags. This indicates that we want our permission to be propagated to all child directories&nbsp;<em>and<\/em>&nbsp;files.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Inheritance Flag<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>ContainerInherit<\/td><td>Propagate to child containers (directories).<\/td><\/tr><tr><td>None<\/td><td>Do not propagate this permission to any child containers or objects.<\/td><\/tr><tr><td>ObjectInherit<\/td><td>Propagate to child objects (files).<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"propagation-flags\">Propagation Flags<\/h2>\n\n\n\n<p>In addtion to Inheritance Flags we can also set Propagation Flags. The default Windows behavior is&nbsp;<code>None<\/code>. See the table below for more detail on the three Propagation Flag options. Setting this flag to&nbsp;<code>InheritOnly<\/code>&nbsp;will cause the access rule to&nbsp;<em>only<\/em>&nbsp;apply to child objects of the container.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Propagation Flag<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>InheritOnly<\/td><td>Specifies that the ACE is propagated only to child objects. This includes both container and leaf child objects.<\/td><\/tr><tr><td>None<\/td><td>Specifies that no inheritance flags are set.<\/td><\/tr><tr><td>NoPropagateInherit<\/td><td>Specifies that the ACE is not propagated to child objects.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"flag-combinations-and-effect\">Flag Combinations and Effect<\/h2>\n\n\n\n<p>The table below details how a rule will be apply to the current object and child objects based on the flags set in the access rule.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Access Rule Applies To<\/th><th>Inheritance Flags<\/th><th>Propagation Flags<\/th><\/tr><\/thead><tbody><tr><td>Subfolders and Files only<\/td><td>ContainerInherit,ObjectInherit<\/td><td>InheritOnly<\/td><\/tr><tr><td>This Folder, Subfolders and Files<\/td><td>ContainerInherit,ObjectInherit<\/td><td>None<\/td><\/tr><tr><td>This Folder, Subfolders and Files<\/td><td>ContainerInherit,ObjectInherit<\/td><td>NoPropagateInherit<\/td><\/tr><tr><td>This folder and Subfolders<\/td><td>ContainerInherit<\/td><td>None<\/td><\/tr><tr><td>Subfolders only<\/td><td>ContainerInherit<\/td><td>InheritOnly<\/td><\/tr><tr><td>This Folder and Files<\/td><td>ObjectInherit<\/td><td>None<\/td><\/tr><tr><td>This Folder and Files<\/td><td>ObjectInherit<\/td><td>NoPropagateInherit<\/td><\/tr><tr><td>This Folder only<\/td><td>None<\/td><td>None<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"access-control-types\">Access Control Types<\/h2>\n\n\n\n<p>There are only two access control types.&nbsp;<code>Allow<\/code>&nbsp;and&nbsp;<code>Deny<\/code>. Allow means we are allowing the permission, e.g., we are allowing a user to write to this directly. Deny will specifically deny a right, and takes precedence over Allow permissions. So, if a user has a Modify\/Allow entry and also a Read\/Deny that user will have all Modify rights&nbsp;<em>except<\/em>&nbsp;read.<\/p>\n\n\n\n<p>Be sure to verify a principal\u2019s effective access when using&nbsp;<code>Deny<\/code>&nbsp;types.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"basic-permissions\">Basic Permissions<\/h2>\n\n\n\n<p>When we talk about basic permissions we are talking about the primary checkboxes available when looking at the security tab in a file system object\u2019s Properties dialog.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/luke_arntz_explorer_basic.png\" alt=\"Basic Permissions\"\/><\/figure>\n\n\n\n<p>Here is a table of basic permissions that can be set via PowerShell, and the rights each will grant.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Permission<\/th><th>Rights Granted<\/th><\/tr><\/thead><tbody><tr><td>FullControl<\/td><td>Specifies the right to exert full control over a folder or file, and to modify access control and audit rules. This value represents the right to do anything with a file and is the combination of all rights in this enumeration.<\/td><\/tr><tr><td>Modify<\/td><td>Specifies the right to read, write, list folder contents, delete folders and files, and run application files. This right includes the ReadAndExecute right, the Write right, and the Delete right.<\/td><\/tr><tr><td>ReadAndExecute<\/td><td>Specifies the right to open and copy folders or files as read-only, and to run application files. This right includes the Read right and the ExecuteFile right.<\/td><\/tr><tr><td>Read<\/td><td>Specifies the right to open and copy folders or files as read-only. This right includes the ReadData right, ReadExtendedAttributes right, ReadAttributesright, and ReadPermissions right.<\/td><\/tr><tr><td>Write<\/td><td>Specifies the right to create folders and files, and to add or remove data from files. This right includes the WriteData right, AppendData right, WriteExtendedAttributes right, and WriteAttributes right.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Note that&nbsp;<code>List folder contents<\/code>&nbsp;is not in the table above. While this can be set via PowerShell it will show up under&nbsp;<em>Special permissions<\/em>&nbsp;as&nbsp;<code>List folder \/ read data<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"adding-basic-permissions\">Adding Basic Permissions<\/h3>\n\n\n\n<p>To add new rights to a folder we will need to first create a file system rule, and then we can add it to our current set of&nbsp;<code>$acl<\/code>. There are two methods we can use to either add or set a rule.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"setaccessrule-vs-addaccessrule\">SetAccessRule() vs AddAccessRule()<\/h4>\n\n\n\n<p>The first method is&nbsp;<code>SetAccessRule()<\/code>. When using&nbsp;<code>SetAccessRule()<\/code>&nbsp;our new rule will&nbsp;<em>overwrite<\/em>&nbsp;any existing rule of the same type (Allow or Deny) for that security principal (user or group) regardless of the existing permissions. If a user has Modify permission and a new rule is created using&nbsp;<code>SetAccessRule()<\/code>&nbsp;specifying Read permission that user will now&nbsp;<em>only<\/em>&nbsp;have Read permission. This method essentially removes any existing access an replaces that access with the specified rule.<\/p>\n\n\n\n<p>The second method is&nbsp;<code>AddAccessRule()<\/code>. This method will&nbsp;<em>add<\/em>&nbsp;this access rule to the ACL. Here if a user has Modify permission and we use&nbsp;<code>AddAccessRule()<\/code>&nbsp;to create a new rule with Read permission the user will&nbsp;<em>still have Modify permissions<\/em>. This can be dangerous from a security perspective if we think we intend to limit a user\u2019s access, but mistakenly use the&nbsp;<code>AddAccessRule()<\/code>&nbsp;method.<\/p>\n\n\n\n<p>My suggestion is always use&nbsp;<code>SetAccessRule()<\/code>&nbsp;and specify all intended permissions when making ACL changes.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"creating-a-new-filesystem-access-rule\">Creating A New FileSystem Access Rule<\/h4>\n\n\n\n<p>Now that we understand inheritance flags, basic permissions, and the methods used to add a rule to our&nbsp;<code>$acl<\/code>&nbsp;we are ready to create a new filesystem rule. This is a two step process. First we create our rule, and then we will apply it to our&nbsp;<code>$acl<\/code>&nbsp;object.<\/p>\n\n\n\n<p>Here\u2019s what we need to create the rule.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>1<\/code><\/td><td><code><em>$rule<\/em> = <em>New-Object<\/em> System.Security.AccessControl.FileSystemAccessRule(\"DOMAIN\\larntz\",\"Write\",\"ContainerInherit,ObjectInherit\",\"None\",\"Allow\")<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The code block above creates a new object of type&nbsp;<code>System.Security.AccessControl.FileSystemAccessRule<\/code>&nbsp;with the&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.security.accesscontrol.filesystemaccessrule.-ctor?view=netframework-4.8#System_Security_AccessControl_FileSystemAccessRule__ctor_System_Security_Principal_IdentityReference_System_Security_AccessControl_FileSystemRights_System_Security_AccessControl_InheritanceFlags_System_Security_AccessControl_PropagationFlags_System_Security_AccessControl_AccessControlType_\">following parameters<\/a>:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Value<\/th><\/tr><\/thead><tbody><tr><td>identity<\/td><td>DOMAIN\\larntz<\/td><\/tr><tr><td>fileSystemRights<\/td><td>Write<\/td><\/tr><tr><td>inheritanceFlags<\/td><td>ContainerInherit,ObjectInherit<\/td><\/tr><tr><td>propagationFlags<\/td><td>None<\/td><\/tr><tr><td>type<\/td><td>Allow<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>After creating the rule we can apply it to our&nbsp;<code>$acl<\/code>&nbsp;object using the&nbsp;<code>SetAccessRule()<\/code>&nbsp;method.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>1<\/code><\/td><td><code><em>$acl<\/em>.SetAccessRule(<em>$rule<\/em>)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Again, we haven\u2019t modified the filesystem yet. We\u2019ve only modified our&nbsp;<code>$acl<\/code>&nbsp;object. Next let\u2019s look at how to apply our&nbsp;<code>$acl<\/code>&nbsp;object to a filesystem object.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"removing-a-filesystem-access-rule\">Removing A FileSystem Access Rule<\/h4>\n\n\n\n<p>To remove an existing access rule you should use the&nbsp;<code>RemoveAccessRule()<\/code>&nbsp;method. This is very straightfoward once you understand how to create an access rule. To remove a rule it must already be part of the&nbsp;<code>$acl<\/code>&nbsp;object. Generally you would loop through these to find the rule you wanted and assign it to a variable. Then you can call&nbsp;<code>$acl.RemoveAccessRule($rule)<\/code>&nbsp;to remove the rule from the&nbsp;<code>$acl<\/code>&nbsp;object.<\/p>\n\n\n\n<p>Here is a simple example to illustrate. This example demonstrates create an ACL object, create a rule, listing the access rules in our ACL object, and then removing the access rule from the ACL object.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18<\/code><\/td><td><code><em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$acl<\/em> = <em>New-Object<\/em> System.Security.AccessControl.DirectorySecurity <em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$rule<\/em> = <em>New-Object<\/em> System.Security.AccessControl.FileSystemAccessRule(\"DOMAIN\\larntz\",\"Read,CreateFiles\",\"ContainerInherit,ObjectInherit\",\"None\",\"Allow\") <em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$acl<\/em>.SetAccessRule(<em>$rule<\/em>) <em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$acl<\/em>.Access FileSystemRights : CreateFiles, Read, Synchronize AccessControlType : Allow IdentityReference : DOMAIN\\larntz IsInherited : False InheritanceFlags : ContainerInherit, ObjectInherit PropagationFlags : None <em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$acl<\/em>.RemoveAccessRule(<em>$rule<\/em>) True <em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$acl<\/em>.Access <em>PS <\/em>C:\\Users\\larntz\\Documents&gt;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"saving-the-acl-changes\">Saving the ACL Changes<\/h2>\n\n\n\n<p>To avoid a bug in&nbsp;<code>Set-Acl<\/code>&nbsp;we will be using the&nbsp;<code>SetAccessControl()<\/code>&nbsp;method to save our permissions. If we need to be compatible with PowerShell 6 we must use&nbsp;<code>Set-Acl<\/code>, but&nbsp;<a href=\"https:\/\/stackoverflow.com\/a\/31629122\">you may experience odd behavior<\/a>&nbsp;after using it and from personal experience I don\u2019t recommend using&nbsp;<code>Set-Acl<\/code>.<\/p>\n\n\n\n<p>What we are going to do instead is use the&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.io.directoryinfo.setaccesscontrol?view=netframework-4.7.2#System_IO_DirectoryInfo_SetAccessControl_System_Security_AccessControl_DirectorySecurity_\"><code>SetAccessControl()<\/code>&nbsp;method of the&nbsp;<code>DirectoryInfo<\/code><\/a>&nbsp;class to apply our ACL.<\/p>\n\n\n\n<p>To do this we can use Get-Item and then call&nbsp;<code>SetAccessControl()<\/code>&nbsp;on the returned object.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>1<\/code><\/td><td><code>(<em>Get-Item<\/em> .\\Directory\\ChildDirectory\\).SetAccessControl(<em>$acl<\/em>)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Putting all the steps together we can get or create an ACL object, add a rule, and apply that rule to a file system object. The code block below shows all three steps together.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>1 2 3<\/code><\/td><td><code><em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$acl<\/em> = <em>Get-Acl<\/em> .\\Directory\\ <em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$rule<\/em> = <em>New-Object<\/em> System.Security.AccessControl.FileSystemAccessRule(\"DOMAIN\\larntz\",\"Write\",\"ContainerInherit,ObjectInherit\",\"None\",\"Allow\") <em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$acl<\/em>.SetAccessRule(<em>$rule<\/em>)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"special-permissions\">Special Permissions<\/h2>\n\n\n\n<p>A basic right such as Modify can be thought of as a group of special permissions. Special permissions are more detailed rights that can be assigned rather than using the pre-defined basic rights groups. For instance, if you want to allow a principal to create files, but not directories that can be accomplished using special rights. These type permissions are only viewable in the GUI via the Advanced button on the Security tab.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/luke_arntz_explorer_basic.png\" alt=\"Special Permissions\"\/><\/figure>\n\n\n\n<p>At first, it may take some experimentation to get the desired rights when dealing with advanced permissions. Be sure to test these settings thoroughly to be sure everything behaves as intended.<\/p>\n\n\n\n<p>Now, using the example above let\u2019s grant a user&nbsp;<code>Read<\/code>&nbsp;and&nbsp;<code>CreateFiles<\/code>&nbsp;permission only. This will allow a user to read the directory tree and files, but only allow them to&nbsp;<em>paste<\/em>&nbsp;new files into the folders. As you can see in the table below the&nbsp;<code>CreateFiles<\/code>&nbsp;permission does not grant&nbsp;<code>AppendData<\/code>&nbsp;which is needed to change data in an existing file. Also, once the user creates\/moves a file into this directory they will be unable to delete it.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20<\/code><\/td><td><code><em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$acl<\/em> = <em>get-acl<\/em> .\\Directory\\ <em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$rule<\/em> = <em>New-Object<\/em> System.Security.AccessControl.FileSystemAccessRule(\"DOMAIN\\larntz\",\"Read,CreateFiles\",\"ContainerInherit,ObjectInherit\",\"None\",\"Allow\") <em>PS <\/em>C:\\Users\\larntz\\Documents&gt; <em>$acl<\/em>.SetAccessRule(<em>$rule<\/em>) <em>PS <\/em>C:\\Users\\larntz\\Documents&gt; (<em>Get-Item<\/em> .\\Directory\\).SetAccessControl(<em>$acl<\/em>) <em>PS <\/em>C:\\Users\\larntz\\Documents&gt; (<em>Get-Acl<\/em> .\\Directory\\).Access FileSystemRights : FullControl AccessControlType : Allow IdentityReference : BUILTIN\\Administrators IsInherited : False InheritanceFlags : ContainerInherit, ObjectInherit PropagationFlags : None FileSystemRights : CreateFiles, Read, Synchronize AccessControlType : Allow IdentityReference : DOMAIN\\larntz IsInherited : False InheritanceFlags : ContainerInherit, ObjectInherit PropagationFlags : None<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"table-of-special-permissions\">Table of Special Permissions<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Permission<\/th><th>Rights Granted<\/th><\/tr><\/thead><tbody><tr><td>AppendData<\/td><td>Specifies the right to append data to the end of a file.<\/td><\/tr><tr><td>ChangePermissions<\/td><td>Specifies the right to change the security and audit rules associated with a file or folder.<\/td><\/tr><tr><td>CreateDirectories<\/td><td>Specifies the right to create a folder.<\/td><\/tr><tr><td>CreateFiles<\/td><td>Specifies the right to create a file.<\/td><\/tr><tr><td>Delete<\/td><td>Specifies the right to delete a folder or file.<\/td><\/tr><tr><td>DeleteSubdirectoriesAndFiles<\/td><td>Specifies the right to delete a folder and any files contained within that folder.<\/td><\/tr><tr><td>ExecuteFile<\/td><td>Specifies the right to run an application file.<\/td><\/tr><tr><td>ListDirectory<\/td><td>Specifies the right to read the contents of a directory.<\/td><\/tr><tr><td>ReadAttributes<\/td><td>Specifies the right to open and copy file system attributes from a folder or file. For example, this value specifies the right to view the file creation or modified date. This does not include the right to read data, extended file system attributes, or access and audit rules.<\/td><\/tr><tr><td>ReadData<\/td><td>Specifies the right to open and copy a file or folder. This does not include the right to read file system attributes, extended file system attributes, or access and audit rules.<\/td><\/tr><tr><td>ReadExtendedAttributes<\/td><td>Specifies the right to open and copy extended file system attributes from a folder or file. For example, this value specifies the right to view author and content information. This does not include the right to read data, file system attributes, or access and audit rules.<\/td><\/tr><tr><td>ReadPermissions<\/td><td>Specifies the right to open and copy access and audit rules from a folder or file. This does not include the right to read data, file system attributes, and extended file system attributes.<\/td><\/tr><tr><td>Synchronize<\/td><td>Specifies whether the application can wait for a file handle to synchronize with the completion of an I\/O operation.<\/td><\/tr><tr><td>TakeOwnership<\/td><td>Specifies the right to change the owner of a folder or file. Note that owners of a resource have full access to that resource.<\/td><\/tr><tr><td>Traverse<\/td><td>Specifies the right to list the contents of a folder and to run applications contained within that folder.<\/td><\/tr><tr><td>WriteAttributes<\/td><td>Specifies the right to open and write file system attributes to a folder or file. This does not include the ability to write data, extended attributes, or access and audit rules.<\/td><\/tr><tr><td>WriteData<\/td><td>Specifies the right to open and write to a file or folder. This does not include the right to open and write file system attributes, extended file system attributes, or access and audit rules.<\/td><\/tr><tr><td>WriteExtendedAttributes<\/td><td>Specifies the right to open and write extended file system attributes to a folder or file. This does not include the ability to write data, attributes, or access and audit rules.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"references\">References<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"microsoft-docs\">Microsoft Docs<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/microsoft.powershell.security\/get-acl?view=powershell-6\">Get-Acl<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/Microsoft.PowerShell.Management\/Get-Item?view=powershell-6\">Get-Item<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/Microsoft.PowerShell.Utility\/New-Object?view=powershell-6\">New-Object<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.security.accesscontrol.filesystemrights?view=netcore-2.2\">FileSystemRights Enum<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.security.accesscontrol.filesystemsecurity.setaccessrule?view=netcore-2.2#System_Security_AccessControl_FileSystemSecurity_SetAccessRule_System_Security_AccessControl_FileSystemAccessRule_\">SetAccessRule()<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.security.accesscontrol.filesystemsecurity.addaccessrule?view=netcore-2.2\">AddAccessRule()<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.security.accesscontrol.objectsecurity.setowner?view=netcore-2.2#System_Security_AccessControl_ObjectSecurity_SetOwner_System_Security_Principal_IdentityReference_\">SetOwner()<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.io.file.setaccesscontrol?view=netframework-4.8#System_IO_File_SetAccessControl_System_String_System_Security_AccessControl_FileSecurity_\">SetAccessControl()<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Overview Changing NTFS permissions with PowerShell saves a lot of time when you need to make changes to a large group of files or when it is required as part of a larger automation project. This article should help you understand everything you need to know to manipulate security permissions with PowerShell. When changing ownership&#8230;<\/p>\n<p class=\"more-link-wrap\"><a href=\"http:\/\/merserver.com\/index.php\/2022\/10\/20\/changing-ntfs-security-permissions-using-powershell\/\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &ldquo;Changing NTFS Security Permissions using PowerShell&rdquo;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-333","post","type-post","status-publish","format-standard","hentry","category-it"],"_links":{"self":[{"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/posts\/333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/comments?post=333"}],"version-history":[{"count":1,"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/posts\/333\/revisions"}],"predecessor-version":[{"id":336,"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/posts\/333\/revisions\/336"}],"wp:attachment":[{"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/media?parent=333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/categories?post=333"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/tags?post=333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}