Powershell:Get-ACL并获取远程文件夹上特定用户的权限

Ash*_*pta 2 powershell

Get-ACL \\machine_name\folder1 | Format-List *
Run Code Online (Sandbox Code Playgroud)

给我以下包括用户的访问权限(在AccessToString中)

**AccessToString          : NT AUTHORITY\Authenticated Users Allow  AppendData
                          NT AUTHORITY\Authenticated Users Allow  -536805376
                          NT AUTHORITY\SYSTEM Allow  FullControl
                          BUILTIN\Administrators Allow  FullControl
                          BUILTIN\Users Allow  ReadAndExecute, Synchronize**
AuditToString           :
AccessRightType         : System.Security.AccessControl.FileSystemRights
AccessRuleType          : System.Security.AccessControl.FileSystemAccessRule
AuditRuleType           : System.Security.AccessControl.FileSystemAuditRule
AreAccessRulesProtected : True
AreAuditRulesProtected  : False
AreAccessRulesCanonical : True
AreAuditRulesCanonical  : True
Run Code Online (Sandbox Code Playgroud)

但下面给我空了:

Get-ACL \\machine_name\folder1| Format-List * | select AccessToString
Run Code Online (Sandbox Code Playgroud)

最终,我想获取AccessToString中特定给定用户的条目,例如,只获取"BUILTIN\Administrators"的访问权限.将不胜感激任何帮助.

Cos*_*Key 8

首先,不应该将任何Format-*cmdlet的输出传递给其他cmdlet.为什么?因为Format-*cmdlet的输出不是您在管道上使用的对象.它们是用于在屏幕上形成信息的专用对象.

如果我们接受命令,Get-Acl c:\ | Format-List * | Get-Member我们将看到这五种.NET类型中有五个对象从Format-List cmdlet传递到Get-Member cmdlet:

  • Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
  • Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
  • Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
  • Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
  • Microsoft.PowerShell.Commands.Internal.Format.FormatEndData

这些对象只有格式列表才能很好地显示.此外,Get-Member不会显示任何这些对象具有任何AccessToString属性.

AccessToString属性只是表示ACL的一小段文本.这不适合过滤,而应该做的是潜入Access属性并过滤其IdentityReference属性上的访问控制条目(ACE).

你会有更好的运气:

Get-Acl c:\ | Select-Object -ExpandProperty Access | 
  Where-Object identityreference -eq "BUILTIN\Administrators"
Run Code Online (Sandbox Code Playgroud)