Msvm_HeartbeatComponentをVBScriptで取得する方法

0016

Hyper-V上のゲストOSのハートビートの値を取得します。

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\virtualization") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Msvm_HeartbeatComponent",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Msvm_HeartbeatComponent instance"
    Wscript.Echo "-----------------------------------"
    If isNull(objItem.AdditionalAvailability) Then
        Wscript.Echo "AdditionalAvailability: "
    Else
        Wscript.Echo "AdditionalAvailability: " & Join(objItem.AdditionalAvailability, ",")
    End If
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "CreationClassName: " & objItem.CreationClassName
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "DeviceID: " & objItem.DeviceID
    Wscript.Echo "ElementName: " & objItem.ElementName
    Wscript.Echo "EnabledDefault: " & objItem.EnabledDefault
    Wscript.Echo "EnabledState: " & objItem.EnabledState
    Wscript.Echo "ErrorCleared: " & objItem.ErrorCleared
    Wscript.Echo "ErrorDescription: " & objItem.ErrorDescription
    Wscript.Echo "HealthState: " & objItem.HealthState
    If isNull(objItem.IdentifyingDescriptions) Then
        Wscript.Echo "IdentifyingDescriptions: "
    Else
        Wscript.Echo "IdentifyingDescriptions: " & Join(objItem.IdentifyingDescriptions, ",")
    End If
    Wscript.Echo "InstallDate: " & objItem.InstallDate
    Wscript.Echo "LastErrorCode: " & objItem.LastErrorCode
    Wscript.Echo "LocationIndicator: " & objItem.LocationIndicator
    Wscript.Echo "MaxQuiesceTime: " & objItem.MaxQuiesceTime
    Wscript.Echo "Name: " & objItem.Name
    If isNull(objItem.OperationalStatus) Then
        Wscript.Echo "OperationalStatus: "
    Else
        Wscript.Echo "OperationalStatus: " & Join(objItem.OperationalStatus, ",")
    End If
    Wscript.Echo "OtherEnabledState: " & objItem.OtherEnabledState
    If isNull(objItem.OtherIdentifyingInfo) Then
        Wscript.Echo "OtherIdentifyingInfo: "
    Else
        Wscript.Echo "OtherIdentifyingInfo: " & Join(objItem.OtherIdentifyingInfo, ",")
    End If
    If isNull(objItem.PowerManagementCapabilities) Then
        Wscript.Echo "PowerManagementCapabilities: "
    Else
        Wscript.Echo "PowerManagementCapabilities: " & Join(objItem.PowerManagementCapabilities, ",")
    End If
    Wscript.Echo "PowerManagementSupported: " & objItem.PowerManagementSupported
    Wscript.Echo "PowerOnHours: " & objItem.PowerOnHours
    Wscript.Echo "RequestedState: " & objItem.RequestedState
    Wscript.Echo "Status: " & objItem.Status
    If isNull(objItem.StatusDescriptions) Then
        Wscript.Echo "StatusDescriptions: "
    Else
        Wscript.Echo "StatusDescriptions: " & Join(objItem.StatusDescriptions, ",")
    End If
    Wscript.Echo "StatusInfo: " & objItem.StatusInfo
    Wscript.Echo "SystemCreationClassName: " & objItem.SystemCreationClassName
    Wscript.Echo "SystemName: " & objItem.SystemName
    Wscript.Echo "TimeOfLastStateChange: " & objItem.TimeOfLastStateChange
    Wscript.Echo "TotalPowerOnHours: " & objItem.TotalPowerOnHours
Next

SystemNameをコンピュータ名に変換する必要がある場合には、Msvm_ComputerSystem等を利用して、実施します。
例えばシステム名”FE1AD57E-1A15-4611-BEA0-76A6C5959114″を表示名に変換する場合には以下のように。

Wscript.Echo "Name: " & SystemName2ElementName("FE1AD57E-1A15-4611-BEA0-76A6C5959114")

Function SystemName2ElementName(strSYSTEMNAME)
	strComputer = "."
	Set objMsvm_ComputerSystem = GetObject("winmgmts:\\" & strComputer & "\root\virtualization") 
	Set colItems = objMsvm_ComputerSystem.ExecQuery("SELECT * FROM Msvm_ComputerSystem Where Name=" & "'" & strSYSTEMNAME & "'",,48)
	For Each objItem in colItems
	    SystemName2ElementName = objItem.ElementName
	Next
End Function

参考URL

Msvm_HeartbeatComponent Class

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です