title: Using powershell to set file system ACE
body: <p>I am attempting to set file ACE's using powershell. I have not been able to set the multiple permissions though with the same call to <code>set-acl</code>.</p>
  
  <p>So have resorted to making a function and calling the function for each of the permission grants I want to make. Still, <code>set-acl</code> is failing to set both Modify and Write permission. I am confused now.</p>
  
  <p>I run the script and only get the write permission set. The Function runs without errors, but I don't get the proper ACE set.</p>
  
  <p>I can't really see why the second call to addaccessrule is clobbering the first call?</p>
  
  <pre><code>$StartingDir1 = "C:\_WPCYB"
  $StartingDir2 = "C:\Program Files\Adobe\Adobe InDesign CC 2017\Plug-Ins"
  $WcolRights = [System.Security.AccessControl.FileSystemRights]"Write" 
  $McolRights = [System.Security.AccessControl.FileSystemRights]"Modify"
  $InheritanceFlag = System.Security.AccessControl.InheritanceFlags]::None 
  $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None 
  $objType = [System.Security.AccessControl.AccessControlType]::Allow 
  $objUser = New-Object System.Security.Principal.NTAccount("HA\Domain Users") 
  
  function set-perm-on-dir ($dir, $perm) {
      # handle the starting directory itself, d1
      echo setting perms on directory $dir setting $perm
      $objACE = New-Object System.Security.AccessControl.FileSystemAccessRule($objUser, WcolRights, $InheritanceFlag, $PropagationFlag, $objType) 
      echo "New ACE is " $objACE
      $d1 = Get-Item $StartingDir1
      $acla = get-acl $d1
      $acla.AddAccessRule($objACE)
      set-acl -Path $d1.FullName -AclObject $acla
  }
  
  set-perm-on-dir -dir $StartingDir1 -perm $WcolRights 
  set-perm-on-dir -dir $StartingDir1 -perm $McolRights
  </code></pre>