如果我没有Select
Access
属性,那么将根据需要显示内容。例如BUILTIN\Administrators Allow FullControl
。
但是如果我Select
的{{1}}属性,则会显示某种对象类型(Access
):
System.Security.AccessControl.FileSystemAccessRule
我对bash的了解比对PowerShell更为熟悉。但是我知道PowerShell倾向于传递对象而不是字符串。
这两个为什么显示的PS C:\tmp> Get-Acl .\test | Format-List
Path : Microsoft.PowerShell.Core\FileSystem::C:\tmp\test
Owner : EXAMPLE\sjobs
Group : EXAMPLE\Domain Users
Access : BUILTIN\Administrators Allow FullControl
BUILTIN\Administrators Allow 268435456
NT AUTHORITY\SYSTEM Allow FullControl
NT AUTHORITY\SYSTEM Allow 268435456
BUILTIN\Users Allow ReadAndExecute, Synchronize
NT AUTHORITY\Authenticated Users Allow Modify, Synchronize
NT AUTHORITY\Authenticated Users Allow -536805376
Audit :
Sddl : REDACTED
PS C:\tmp> Get-Acl .\test | Select Access | Format-List
Access : {System.Security.AccessControl.FileSystemAccessRule, System.Security.AccessControl.FileSystemAccessRule,
System.Security.AccessControl.FileSystemAccessRule, System.Security.AccessControl.FileSystemAccessRule...}
不同?
更重要的是,如何根据需要仅显示Access
属性?
答案 0 :(得分:4)
如果查看对象类型,它会提供一些线索。
PS C:\Users\jacob> $acl = get-acl
PS C:\Users\jacob> $acl.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False DirectorySecurity System.Security.AccessControl.FileSystemSecurity
PS C:\Users\jacob> ($acl | select access).getType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False PSCustomObject System.Object
使用PSCustomObject
,您可以使用.psobject.Properties.value
或.
表示法访问属性值。
因此,如果我们隔离访问对象$access = $acl | select access
,然后访问属性值,那么我们将获得所需的信息。
PS C:\Users\jacob> $access.PSObject.Properties.Value
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : NT AUTHORITY\SYSTEM
IsInherited : False
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : BUILTIN\Administrators
IsInherited : False
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : SURFACE\jacob
IsInherited : False
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
一行:
get-acl .\test | select access | % { $_.PSObject.Properties.Value }
或者我们可以将其缩小到
get-acl .\test | select access | % { $_.Access }
或者最后:
(get-acl .\test | select access).access