如何列出PowerShell对象的所有属性

lar*_*400 110 powershell

当我看Win32_ComputerSystem类,它表明类似性质的负荷Status,PowerManagementCapabilities等等.然而,当在PowerShell中我做了以下我只拿回一对夫妇:

PS C:\Windows\System32\drivers> Get-WmiObject -Class "Win32_computersystem"

Domain              : YYY.com
Manufacturer        : VMware, Inc.
Model               : VMware Virtual Platform
Name                : LONINEGFQEF58
PrimaryOwnerName    : Authorised User
TotalPhysicalMemory : 2147016704
Run Code Online (Sandbox Code Playgroud)

我怎样才能看到所有房产?

Kei*_*ill 127

试试这个:

Get-WmiObject -Class "Win32_computersystem" | Format-List *
Get-WmiObject -Class "Win32_computersystem" | Format-List -Property *
Run Code Online (Sandbox Code Playgroud)

对于某些对象,PowerShell提供了一组格式说明,这些说明可以影响表格或列表格式.这些通常意味着将大量属性的显示限制为基本属性.但有时你真的想看到一切.在这些情况下Format-List *将显示所有属性.请注意,在您尝试查看PowerShell错误记录的情况下,您需要使用"Format-List*-Force"来真正查看所有错误信息,例如,

$error[0] | Format-List * -force
Run Code Online (Sandbox Code Playgroud)

请注意,通配符可以像传统的wilcard一样使用:

Get-WmiObject -Class "Win32_computersystem" | Format-List M*
Run Code Online (Sandbox Code Playgroud)


man*_*lds 34

如果您想知道有哪些属性(和方法):

Get-WmiObject -Class "Win32_computersystem" | Get-Member
Run Code Online (Sandbox Code Playgroud)

  • 由于原始问题的措辞,我不打算让你失望.但值得指出的是,Get-Member不会仅列出属性及其值,而是列出属性/方法的名称和类型. (5认同)

小智 26

您还可以使用:

Get-WmiObject -Class "Win32_computersystem" | Select *
Run Code Online (Sandbox Code Playgroud)

这将显示与此处其他答案中使用的Format-List*相同的结果.

  • 这实际上比接受的答案中的方法更好,因为使用这种方法你仍然有丰富的对象,而使用`Format-List`会破坏管道中的所有对象. (3认同)

js2*_*010 6

我喜欢

 Get-WmiObject Win32_computersystem | format-custom *
Run Code Online (Sandbox Code Playgroud)

那似乎扩大了一切。

PowerShellCookbook模块中还有一个show-object命令,可以在GUI中执行。PowerShell的创建者Jeffrey Snover在其未插入的视频中使用了它(推荐)。

虽然我经常使用

Get-WmiObject Win32_computersystem | fl *
Run Code Online (Sandbox Code Playgroud)

避免使用.format.ps1xml文件为对象类型定义表或列表视图(如果有)。格式文件甚至可以定义与任何属性名称都不匹配的列标题。

  • `format-custom *`似乎是_really_显示所有内容的答案 (4认同)