1
votes

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.

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:

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

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,..

$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

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.

I'm all out of ideas...

Edit 22 nov - part 1

As requested in the comments:

PS N:\WERVEN> $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> $error[0].exception.innerexception| select *

PS N:\WERVEN> 

Edit 22 nov - part 2

There seems to be some 'known' problem with assigning permissions on synology nas's: http://mikebeach.org/2014/12/06/acl-fix-for-synology-diskstations/

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.

Takes up some more time.. but it works. And I can get some sleep.

2
Right after you get the error, could you do the following and post output: $error[0].exception|select *; $error[0].exception.innerexception| select *. If another error occurs between the time your problem happens and you do the command above, then $error[0] won't be referring to the issue any longer. $error[0] is always the most recent error.Χpẘ
That HResult is 0x80131509 UIA_E_INVALIDOPERATION Indicates that the method attempted an operation that was not valid. - Unfortunately not really new information, except that it comes from the UI automation (what only confirmes your observations). No idea ...JensG

2 Answers

0
votes

I'd say remove the -AclObject parameter name, it does not exist (on PowerShell 5 at least). This works on my computer (I specified absolute paths to test) :

$TemplateAcl = Get-Acl ".\{TEMPLATE}"

Set-Acl ".\OTHER" $TemplateAcl
0
votes

There doesn't seem to be any quick answer for this. For some reason it's not possible to use Set-Acl on a synology nas.

Anywhere you look you're referred to the tool 'synoacltool'. Absurd!