棘手使用Get-Acl

时间:2015-09-02 21:38:55

标签: powershell

使用Get-ACL cmdlet时,它会返回一个有点难以处理的对象。

Path  Owner               Access                                                                                            
----  -----               ------                                                                                            
Test2 Owner               NT AUTHORITY\Authenticated Users Allow  Modify, Synchronize                                       
                          NT AUTHORITY\SYSTEM Allow  FullControl  

使用类似(Get-ACL D:\test2).Access的内容可以提供更好的输出 - 每个权限的项目:

FileSystemRights  : Modify, Synchronize
AccessControlType : Allow
IdentityReference : NT AUTHORITY\Authenticated Users
IsInherited       : False
InheritanceFlags  : ContainerInherit, ObjectInherit
PropagationFlags  : None

FileSystemRights  : FullControl
AccessControlType : Allow
IdentityReference : NT AUTHORITY\SYSTEM
IsInherited       : False
InheritanceFlags  : ContainerInherit, ObjectInherit
PropagationFlags  : None

由于我的其余脚本的工作方式,这是我在Get-ACL操作后需要呈现的内容。但是,我的其余部分嵌套在此For-Each的{​​{1}}之内,当使用上面的示例时,您无法调用Get-ACL,因为此调用似乎只能正常工作直接关注常规$acl.AddAccessRule而非$acl = Get-ACL "Some Path"

我看到的错误是:

$acl = (get-ACL "some path").Access

有没有解决方法,我会看到示例2中的信息,但仍然可以调用Method invocation failed because [System.Security.AccessControl.FileSystemAccessRule] does not contain a method named 'AddAccessRule'. 而无需再运行另一个.AddAccessRule只是为了能够执行此操作?< / p>

1 个答案:

答案 0 :(得分:1)

使用类似的东西:

$acl = Get-Acl "Some Path"
$access = $acl.Access

# Do stuff with $access
$acl.AddAccessRule