为什么驱动器根目录上的 Set-Acl 尝试设置“对象”的所有权?
我想更改 C:
驱动器的 ACL。我想做的是删除用户可以直接在驱动器上创建文件夹的权限。我在编写脚本时在另一个文件夹上测试了该脚本。它工作没有问题。完成后,我在实际驱动器的测试环境中尝试了该脚本。我收到一个我无法弄清楚的错误。如果我手动删除权限,它就可以正常工作。有人有主意吗?
$path = "C:\"
$colRights = [System.Security.AccessControl.FileSystemRights]"CreateDirectories"
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType =[System.Security.AccessControl.AccessControlType]::Allow
$objUser = New-Object System.Security.Principal.NTAccount("Authenticated Users")
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)
$objACL = Get-ACL $path
$objACL.RemoveAccessRule($objACE)
Set-ACL $path $objACL
错误是:
Set-Acl : The security identifier is not allowed to be the owner of this object.
At C:\Users\mhodler\Desktop\Remove Permission.ps1:57 char:8
+ Set-ACL <<<< $path $objACL
+ CategoryInfo : InvalidOperation: (C:\:String) [Set-Acl], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.SetAclCommand
I would like to change the ACL of the C:
drive. What im trying to do is remove the permission that a user can create a folder directly on the drive. I tested the script on another folder while writing it. It worked without a problem. After completion i tried the script in our test envoirnment on the actual drive. I get an error that i cant figure out. If i remove the permission manualy it works without a problem. Anyone got an idea?
$path = "C:\"
$colRights = [System.Security.AccessControl.FileSystemRights]"CreateDirectories"
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType =[System.Security.AccessControl.AccessControlType]::Allow
$objUser = New-Object System.Security.Principal.NTAccount("Authenticated Users")
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)
$objACL = Get-ACL $path
$objACL.RemoveAccessRule($objACE)
Set-ACL $path $objACL
The error is:
Set-Acl : The security identifier is not allowed to be the owner of this object.
At C:\Users\mhodler\Desktop\Remove Permission.ps1:57 char:8
+ Set-ACL <<<< $path $objACL
+ CategoryInfo : InvalidOperation: (C:\:String) [Set-Acl], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.SetAclCommand
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我找到了答案。微软说
将
Get-Acl
调用替换为I found the answer. Microsoft says
Replace the
Get-Acl
call with您需要
SeRestorePrivilege
来设置所有者。我使用下面 URL 中的 Lee Holmes 脚本来通过此附加权限提升我的进程,并且能够将所有者设置为除我之外的其他人。http://www.leeholmes.com/ blog/2010/09/24/ adjustment-token-privileges-in-powershell/
我尝试了
(get-item $path).getaccesscontrol("access")
方法,但仍然遇到相同的错误,因为我的进程没有SeRestorePrivilege
。You need the
SeRestorePrivilege
to set the owner. I used Lee Holmes' script from the URL below to elevate my process with this additional priv and was able to set the owner to someone other than myself.http://www.leeholmes.com/blog/2010/09/24/adjusting-token-privileges-in-powershell/
I tried the
(get-item $path).getaccesscontrol("access")
method but still got the same error since my process didn't have theSeRestorePrivilege
.下面的代码对我有用:
The below code works for me:
人们可能会发现这更容易:
People may find this easier:
$Acl = (Get-Item $Path).GetAccessControl('Access')
为我工作。
我从 CMD 运行我的 PS 脚本,在这个 PS 脚本中我运行另一个 PS 脚本,只要我用我自己的用户执行它,一切都会正常工作。当我使用不同的用户时,我收到相同的错误:
Set-Acl :安全标识符不允许成为该对象的所有者。
只需将 Get-ACL 更改为上面的那一行即可,效果很好。
再次感谢。
$Acl = (Get-Item $Path).GetAccessControl('Access')
Worked for me.
I run my PS Script from CMD and in this PS Script i run another PS Script everything works fine as long as i do it with my own User. When i use different User i get the same Error:
Set-Acl : The security identifier is not allowed to be the owner of this object.
Just changed Get-ACL to that Line above and it worked fine.
Thanks again.