【发布时间】:2014-10-27 13:04:01
【问题描述】:
我有一个特定文件夹 (C:\Windows\winsxs\amd64_microsoft-windows-wpd-portabledeviceapi_31bf3856ad364e35_6.1.7601.17514_none_a926cbb502a97a6e),我需要能够通过 powershell 脚本更改其权限。
我需要能够让系统能够在此文件夹中创建文件。
当我检查 Get-Acl 命令时,它显示 NT Authority\System 已经是文件夹的所有者了?通过 Set-ACL 运行以使该系统帐户能够创建文件的最佳命令是什么?
提前致谢。
(到目前为止,我已经尝试过这段代码......但我的访问被拒绝)
$folder = "C:\Windows\winsxs\amd64_microsoft-windows-wpd-portabledeviceapi_31bf3856ad364e35_6.1.7601.17514_none_a926cbb502a97a6e"
$myUser = "NT AUTHORITY\SYSTEM"
$acl = Get-Acl $folder
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$myUser", "ReadData", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$myUser", "CreateFiles", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$myUser", "AppendData", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
Set-Acl $folder $acl
Set-Acl : Attempted to perform an unauthorized operation.
At line:10 char:1
+ Set-Acl $folder $acl
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Windows\wins...926cbb502a97a6e:String) [Set-Acl], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetAclCommand
【问题讨论】:
-
你是从提升的提示符下运行这个吗?
-
我从提升的提示符下运行它。如果我只想允许访问 Winsxs 中的特定文件夹以允许系统创建文件(不删除等),我需要编写什么脚本?我最好只在文件夹上使用 takeown 然后在上面运行我的脚本吗?
标签: powershell acl