Get-Acl的巧妙使用

  • 本文关键字:Get-Acl powershell
  • 更新时间 :
  • 英文 :


使用Get-ACL cmdlet时,它返回单个对象,处理起来有点麻烦。

Path  Owner               Access                                                                                            
----  -----               ------                                                                                            
Test2 Owner               NT AUTHORITYAuthenticated Users Allow  Modify, Synchronize                                       
                          NT AUTHORITYSYSTEM Allow  FullControl  

使用像(Get-ACL D:test2).Access这样的东西会得到更好的输出-每个权限一个项目:

FileSystemRights  : Modify, Synchronize
AccessControlType : Allow
IdentityReference : NT AUTHORITYAuthenticated Users
IsInherited       : False
InheritanceFlags  : ContainerInherit, ObjectInherit
PropagationFlags  : None
FileSystemRights  : FullControl
AccessControlType : Allow
IdentityReference : NT AUTHORITYSYSTEM
IsInherited       : False
InheritanceFlags  : ContainerInherit, ObjectInherit
PropagationFlags  : None

由于我脚本的其余部分的工作方式,这是我需要在Get-ACL操作后呈现的。然而,我的脚本的其余部分嵌套在Get-ACLFor-Each中,当使用上面的例子时,你不能调用$acl.AddAccessRule,因为这个调用似乎只直接工作在一个常规的$acl = Get-ACL "Some Path"而不是$acl = (get-ACL "some path").Access

我看到的错误是:
Method invocation failed because [System.Security.AccessControl.FileSystemAccessRule] does not contain a method named 'AddAccessRule'.

是否有一种方法可以解决这个问题,即我在示例2中提供了信息,但仍然可以调用.AddAccessRule,而无需运行另一个Get-ACL才能做到这一点?

使用如下代码:

$acl = Get-Acl "Some Path"
$access = $acl.Access
# Do stuff with $access
$acl.AddAccessRule

最新更新