首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell将域用户添加到ntfs权限到文件中

Powershell将域用户添加到ntfs权限到文件中
EN

Stack Overflow用户
提问于 2021-07-06 07:30:44
回答 1查看 488关注 0票数 0

我试图编写一个脚本,其中一部分从文件中获取ACL,并添加特定的用户ntfs权限来修改:

代码语言:javascript
复制
$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

  • $Acl.AddAccessRule($ACE)

  • ~~~~~~~~~~~~~~~~~~~~~~~~

代码语言:javascript
复制
- CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
- FullyQualifiedErrorId : ArgumentException

看起来这些参数不是传递给函数的,但是如果我一个一个地输出它们,它看起来很好

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-06 07:58:08

我认为您只是忘记创建新的访问规则,但是,由于您更改的是文件的ACL,而不是目录,您应该为只有3个参数的新规则使用构造函数,因为文件没有子对象来传播或继承访问权限:

代码语言:javascript
复制
$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 $Acl
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68266312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档