我试图编写一个脚本,其中一部分从文件中获取ACL,并添加特定的用户ntfs权限来修改:
$identity = "$domain\$adname" #In this example $domain='muzi.local $adname='puzi'
$rights = 'Modify'
$inheritance = 'ContainerInherit, ObjectInherit'
$propagation = 'None'
$type = 'Allow'
$Acl = Get-Acl -Path "$bucketdir\$_" #for this example c:\bla.txt
$Acl.AddAccessRule($ACE) #this is where the error output.
Set-Acl -Path "$bucketdir\$_" -AclObject $Acl #code would not get here错误输出:调用带有"1“参数的"AddAccessRule”的异常:“不能设置标志。参数名称: inheritanceFlags”位于C:\Step2.ps1:26 char:3
- CategoryInfo : NotSpecified: (:) [], MethodInvocationException
- FullyQualifiedErrorId : ArgumentException看起来这些参数不是传递给函数的,但是如果我一个一个地输出它们,它看起来很好
发布于 2021-07-06 07:58:08
我认为您只是忘记创建新的访问规则,但是,由于您更改的是文件的ACL,而不是目录,您应该为只有3个参数的新规则使用构造函数,因为文件没有子对象来传播或继承访问权限:
$identity = "$domain\$adname" #In this example $domain='muzi.local $adname='puzi'
$rights = 'Modify'
$type = 'Allow'
# these do not apply for a File (it has no child objects)
# $inheritance = 'ContainerInherit, ObjectInherit'
# $propagation = 'None'
$file = "$bucketdir\$_" #for this example c:\bla.txt
# create the new AccessRule
$rule = [System.Security.AccessControl.FileSystemAccessRule]::new($identity, $rights, $type)
$Acl = Get-Acl -Path $file
$Acl.AddAccessRule($rule)
Set-Acl -Path $file -ACLObject $Aclhttps://stackoverflow.com/questions/68266312
复制相似问题