title: Getting an error code 1 on Set-Acl on a network drive
body: <p>I have a folder structure with damaged permissions restored on a new NAS (synology). All folders (+1000) contain the same structure with 13 subfolders, each with their specific permissions.</p>
  
  <p>I have an 'example' structure on the same drive and I'm now trying to get/set the acl on the different folders. But every time I try to 'Set-Acl' I'm receiving this kind of error:</p>
  
  <pre><code>Set-Acl : Method failed with unexpected error code 1.
  At line:1 char:1
  + Set-Acl -Path ".\1019 Stekene Molenbergstraat" -AclObject $MainAcl
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (N:\WERVEN\WERVE...Molenbergstraat:String) [Set-Acl], InvalidOperationException
      + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.SetAclCommand
  </code></pre>
  
  <p>I've tried many different things..
  Directly on UNC, mapped as a drive, used combinations of Get-Acl, Set-Acl, GetAccessControl('Access'), SetAccessControl($acl), absolute paths, relative paths,..</p>
  
  <pre><code>$TemplateAcl = Get-Acl ".\{TEMPLATE}"
  Set-Acl -Path ".\OTHER" -AclObject $TemplateAcl
  # Error..
  
  $TemplateItem = Get-Item ".\{TEMPLATE}";
  $TemplateAcl = $TemplateItem.GetAccessControl('Access');
  Set-Acl -Path ".\OTHER" -AclObject $TemplateAcl
  # Error...
  
  $OtherItem = Get-Item ".\OTHER";
  $OtherItem.SetAccessControl($TemplateAcl);
  # No error.. but nothing has changed
  </code></pre>
  
  <p>I have full access to this drive. I can set permissions in windows just fine. Using robocopy, I can copy a structure maintaining it's permissions. In PowerShell... I keep getting this error code 1.</p>
  
  <p>I'm all out of ideas...</p>
  
  <p><strong>Edit 22 nov - part 1</strong></p>
  
  <p>As requested in the comments:</p>
  
  <pre><code>PS N:\WERVEN&gt; $error[0].exception|select *;
  
  
  Message        : Method failed with unexpected error code 1.
  Data           : {}
  InnerException : 
  TargetSite     : Void Persist(System.String, System.Runtime.InteropServices.SafeHandle, System.Security.AccessControl.AccessControlSections, System.Object)
  StackTrace     :    at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, SafeHandle handle, AccessControlSections includeSections, Object 
                   exceptionContext)
                      at System.Security.AccessControl.FileSystemSecurity.Persist(String fullPath)
                      at Microsoft.PowerShell.Commands.FileSystemProvider.SetSecurityDescriptor(String path, ObjectSecurity sd, AccessControlSections sections)
                      at Microsoft.PowerShell.Commands.FileSystemProvider.SetSecurityDescriptor(String path, ObjectSecurity securityDescriptor)
                      at System.Management.Automation.SessionStateInternal.SetSecurityDescriptor(CmdletProvider providerInstance, String path, ObjectSecurity 
                   securityDescriptor, CmdletProviderContext context)
  HelpLink       : 
  Source         : mscorlib
  HResult        : -2146233079
  
  
  
  
  PS N:\WERVEN&gt; $error[0].exception.innerexception| select *
  
  PS N:\WERVEN&gt; 
  </code></pre>
  
  <p><strong>Edit 22 nov - part 2</strong></p>
  
  <p>There seems to be some 'known' problem with assigning permissions on synology nas's: <a href="http://mikebeach.org/2014/12/06/acl-fix-for-synology-diskstations/" rel="nofollow">http://mikebeach.org/2014/12/06/acl-fix-for-synology-diskstations/</a></p>
  
  <p>Since I was loosing way too much time on this I have fixed my problem by expanding my script using ROBOCOPY to MOVE the folder per folder to a local disc. On this local disc I fix the permissions and /MOVE /SEC /E the folder back to the NAS.</p>
  
  <p>Takes up some more time.. but it works. And I can get some sleep.</p>