title: Export/import ACL using csv
body: <p>I want to export in a csv file the ACL of every subfolder starting from a root folder and then to import them of mirroring folders on another computer.</p>
  
  <p>I'm using this code to export from C:\Users\user\Desktop\a :</p>
  
  <pre><code>Get-ChildItem "C:\Users\user\Desktop\a" -Recurse | ?{ $_.PsIsContainer } | %{
  $Path = $_.FullName
  # Exclude inherited rights from the report
  (Get-Acl $Path).Access | ?{ !$_.IsInherited } | Select-Object `
      @{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
      InheritanceFlags, PropagationFlags, FileSystemRights
  } | Export-CSV "C:\Users\user\Desktop\Permissions.csv"
  </code></pre>
  
  <p>and this code to import ACL:</p>
  
  <pre><code>$par = Import-Csv -Path "C:\Users\user\Desktop\Permissions.csv"
  foreach ( $i in $par ) { 
      $path= $i.Path
      $IdentityReference= $i.IdentityReference
      $AccessControlType=$i.AccessControlType
      $InheritanceFlags= $i.InheritanceFlags
      $PropagationFlags=$i.PropagationFlags
      $FileSystemRights=$i.FileSystemRights
      echo $path $IdentityReference
      $acl = Get-Acl C:\Users\user\Desktop
      $permission = $i.IdentityReference,$i.FileSystemRights,$i.AccessControlType
      $accessRule = new-object System.Security.AccessControl.FileSystemAccessRule $permission
      $acl.SetAccessRule($accessRule)
      $acl | Set-Acl $path
  }
  </code></pre>
  
  <p>Permissions.csv is something like this:</p>
  
  <pre><code>#TYPE Selected.System.Security.AccessControl.FileSystemAccessRule
  "Path","IdentityReference","AccessControlType","InheritanceFlags","PropagationFlags","FileSystemRights"
  "C:\Users\user\Desktop\a\b","DITOADMIN\pluto","Allow","None","None","ReadAndExecute, Synchronize"
  "C:\Users\user\Desktop\a\b\c","DITOADMIN\pluto","Allow","ContainerInherit, ObjectInherit","None","ReadAndExecute, Synchronize"
  "C:\Users\user\Desktop\a\b\c","DITOADMIN\admin","Allow","None","None","FullControl"
  "C:\Users\user\Desktop\a\b\c","DITOADMIN\pippo","Allow","ContainerInherit, ObjectInherit","None","ReadAndExecute, Synchronize"
  </code></pre>
  
  <p>unfortunately, import action doesn't work since only last permission is imported (so only for pippo user and not for pluto).</p>
  
  <p>anybody knows why?</p>