通过 Winrm 查询 WMI 时如何检索属性的数据类型

通过 Winrm 查询 WMI 时如何检索属性的数据类型

Winrm 允许我通过 WS-MAN 协议(而不是 DCOM)查询 WMI。但是,在 DCOM 实现中,我可以检索我查询的各种类的各种属性的数据类型。但是,如果我使用 winrm,我只会返回值。有什么方法可以查询数据类型吗?

例如 c:> winrm enum wmicimv2/* -dialect:wql -filter:"Select * FROM Win32_ComputerSystem"

将会返回类似

    <wsman:Results xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman/results">
    <p:Win32_ComputerSystem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_ComputerSystem" xmlns:cim="http://schemas.dmtf.org/wbem/wscim/1/common" xsi:type="p:Win32_ComputerSystem_Type" xml:lang="en-US">

<p:AdminPasswordStatus>3</p:AdminPasswordStatus>
<p:AutomaticManagedPagefile>true</p:AutomaticManagedPagefile>
<p:AutomaticResetBootOption>true</p:AutomaticResetBootOption>
<p:AutomaticResetCapability>true</p:AutomaticResetCapability>
<p:BootOptionOnLimit xsi:nil="true"/><p:BootOptionOnWatchDog xsi:nil="true"/>
<p:BootROMSupported>true</p:BootROMSupported>
<p:BootupState>Normal boot</p:BootupState>
.....

但是,如您所见,数据类型不在那里。我确实知道数据类型,因为这是一个标准的 Win32 对象。架构是在线的,我可以静态地弄清楚。但是,可能存在自定义类。DCOM Wmi 方法允许我查询属性并找到有关它们的更多详细信息,例如它们的数据类型以及它们是否是数组。我可以通过 winrm/wsman 执行相同操作吗?我知道这可以通过 powershell 完成。我正在寻找 winrm/wsman 方法而不是 powershell

谢谢

答案1

您可以通过多种方式执行此操作,这些方式将返回一个包含所有已定义数据类型的对象。然后,您可以获取此对象并获取每个值的数据类型。

$WMI = get-wmiobject -class Win32_ComputerSystem -ComputerName <RemoteComputer>
$WMI.PSObject.Members | where membertype -match "Property"

这会为您提供 WMI 对象,您可以从那里用它做您想做的事情。$WMI.psobject.Members 枚举每个值并允许您循环遍历对象查看每个值。

Get-WmiObject 不使用 WS-Management 连接到远程计算机,因此不需要远程计算机配置 WS-Management。它在这里使用 DCOM。如果您想使用 WinRM,您可以使用

$Results = Invoke-Command -scriptblock { get-wmiobject -class Win32_ComputerSystem } -computerName <ComputerName>

这个变量将是Deserialized.System.Management.ManagementObject#root\cimv2\Win32_ComputerSystem,但带有一些添加的属性。

相关内容