Computers hosting a HyperV instance and those instances

Perhaps there is a different or better way to gather this information, but I had difficulty directly querying the root\virtualization namespace using configuration.mof (and by extension, sms_def.mof).  In order to work around that issue, here’s my summarized process:

    1. I already have this custom mof edit:  http://myitforum.com/cs2/blogs/skissinger/archive/2008/09/27/win32-servercomponent-what-is-it.aspx
    2. Using that, create a collection of Servers which have Hyperv as a feature installed.
    3. Target that collection with a DCM Baseline.  That Baseline has a Configuration Item inside of it with a General type CI, with 1 script based test (see below).
    4. sms_def.mof has this mof edit:

//================== Hyperv instances on a HyperV Host

[ SMS_Report     (TRUE),

SMS_Group_Name ("HypervInst"),

SMS_Class_ID   ("CUSTOM|HypervInst|1.0") ]

class CM_HypervInst : SMS_Class_Template

{

[SMS_Report(TRUE)]      string   Description;

[SMS_Report(TRUE),key]  string   ElementName;

[SMS_Report(TRUE)]      Uint16   EnabledState;

};

 

this is the script that goes inside the DCM ConfigItem:

on error resume next

Dim wbemCimtypeString

Dim wbemCimTypeUint16

wbemCimtypeString = 8

wbemCimTypeUint16 = 18

‘ Remove classes

Set oLocation = CreateObject(“WbemScripting.SWbemLocator”)

Set oServices = oLocation.ConnectServer(,”root\cimv2″)

set oNewObject = oServices.Get(“CM_HyperVInst”)

oNewObject.Delete_

‘==================

‘ Create data class structure

‘==================

Set oDataObject = oServices.Get

oDataObject.Path_.Class = “CM_HyperVInst”

oDataObject.Properties_.add “Description” , wbemCimtypeString

oDataObject.Properties_.add “EnabledState” , wbemCimtypeUint16

oDataObject.Properties_.add “ElementName” , wbemCimtypeString

oDataObject.Properties_(“ElementName”).Qualifiers_.add “key” , True

oDataObject.Put_

‘==================

‘For each instance found in virtualization create a new instance in that

‘WMI namespace we created in root\cimv2

‘==================

Set oServices2 = oLocation.ConnectServer(, “root\Virtualization” )

squery = “select * from MsVM_ComputerSystem”

Set oInstances = oServices2.ExecQuery(sQuery)

‘==================

‘Drop that into a custom wmi Namespace

‘==================

FOR EACH oObject in oInstances

Set oNewObject = oServices.Get(“CM_HyperVInst”).SpawnInstance_

oNewObject.ElementName = oObject.ElementName

oNewObject.Description = oObject.Description

oNewObject.EnabledState = oObject.EnabledState

oNewObject.put_

Next

wscript.quit

 

Here’s a sample report

select

sys1.netbios_name0 [The Host],

case when cast(hv.EnabledState0 as CHAR(20))=’2′ then ‘Running’

when CAST(hv.EnabledState0 as CHAR(20))=’3′ then ‘Stopped/Disabled’

when CAST(hv.EnabledState0 as CHAR(20))=’32769′ then ‘Saved’

when CAST(hv.EnabledState0 as CHAR(20))=’0′ then ‘Unknown’

when CAST(hv.EnabledState0 as CHAR(20))=’32768′ then ‘Paused’

when CAST(hv.EnabledState0 as CHAR(20))=’32770′ then ‘Starting’

when CAST(hv.EnabledState0 as CHAR(20))=’32773′ then ‘Saving’

when CAST(hv.EnabledState0 as CHAR(20))=’32774′ then ‘Stopping’

when CAST(hv.EnabledState0 as CHAR(20))=’32776′ then ‘Pausing’

when CAST(hv.EnabledState0 as CHAR(20))=’32777′ then ‘Resuming’

end as [Enabled State]

, hv.ElementName0 [Instance]

from v_GS_HypervInst0 hv

join v_R_System sys1 on sys1.ResourceID=hv.ResourceID

where hv.Description0 = ‘Microsoft Virtual Machine’

email

Written by , Posted .