1

Winrm allows me to query WMI via the WS-MAN protocol as opposed to DCOM. However, in the DCOM implementation I can retrieve the data types of the various properties of the various classes I query. However, if I use winrm I just get back the values. Is there any way to query the datatypes?

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

Will return something like

    <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>
.....

However, as you can see, the data types are not there. I do know the data types because this is a standard Win32 object. The schema is online and I could statically figure it out. However, there may be custom classes. The DCOM Wmi approach allowed me to query the properties and find out a little more details about them, such as their data type and if they were an array or not. Can I do the same via winrm/wsman. I know this can be done via powershell. I'm looking for a winrm/wsman approach and not powershell

Thanks

1 Answer 1

0

You can do this multiple ways that will return an object which has them all in their defined data type. You can then take this object and get each values data type.

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

This give you the WMI object and you can do what you want with it from there. the $WMI.psobject.Members enumerates each value and allows you to loop through the object looking at each.

the Get-WmiObject is not useing WS-Management to connect to the remote computer and therefore dosen't require the remote machine to have WS-Management configured. It is using DCOM here. If you want to use WinRM you can use

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

The variable in this one will be a Deserialized.System.Management.ManagementObject#root\cimv2\Win32_ComputerSystem but with a few added properties.

5
  • But this is using powershell. This is not using Winrm. Even your second option to use WSMan is pure powershell. I want a non powershell approach. I want to use Winrm. I'm trying to avoid the powershell stack (I have reasons for this). If I can't avoid the powershell stack, then maybe I can at least avoid it from the client side. Can I invoke remote powershell commands from the winrm command line?
    – Mark
    Dec 18, 2013 at 22:19
  • If your trying to avoid PowerShell then I think your going to have to populate your variable types yourself. I understand PowerShell can be resource intensive sometimes but you can also use it to export your wmi call to CLIXML and get your var types that way. If you don't mind me asking why are you trying to avoid the PowerShell stack?
    – TechGuyTJ
    Dec 18, 2013 at 22:58
  • Mainly for performance reasons. I plan on hitting thousands of devices multiple times and every second counts. I'm also trying to avoid DCOM for reliability reasons.
    – Mark
    Dec 19, 2013 at 21:08
  • While I understand performance reasons wouldn't the process of making a connection to a single box multiple times decrease performance? Within PowerShell you can setup sessions to these boxes, making the connection once and then when needing to get more from the box you can use the same connection you already set up. I would think this would greatly increase your performance even while using PowerShell. I would understand a little better if you were only reaching out to a box once. PowerShell in v4 even allows the remote box to reboot and your session will still be active after the reboot.
    – TechGuyTJ
    Dec 19, 2013 at 21:49
  • Thanks for the tip. I am looking into keeping the session alive since it does not seem we can do what I want via pure winrm
    – Mark
    Dec 19, 2013 at 22:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .