public override Object CollectData(IDictionary <String, Object> args) { using (var vmMgmt = WMIHelper.GetFirstInstance(WMI_Namespace, WMI_Class_Msvm_VirtualSystemManagementService)) using (var vm = WMIHelper.QueryFirstInstacne(WMI_Namespace, WMI_Class_Msvm_ComputerSystem, String.Format("Name='{0}'", args["VirtualMachineName"]))) using (var vmSettings = vm.GetRelated(WMI_Class_Msvm_VirtualSystemSettingData)) using (var inParams = vmMgmt.GetMethodParameters(WMI_Method_GetSummaryInformation)) { String[] settingDataPath = new String[vmSettings.Count]; int i = 0; foreach (ManagementObject vmSetting in vmSettings) { settingDataPath[i++] = vmSetting.Path.Path; break; } var data = new Dictionary <String, Object>() { { KeyName_MemoryUsage, null }, { KeyName_MemoryAvailable, null }, { KeyName_AvailableMemoryBuffer, null }, }; if (settingDataPath.Length != 0) { inParams["SettingData"] = settingDataPath; inParams["RequestedInformation"] = new UInt32[] { RequestedInformation_MemoryUsage, RequestedInformation_MemoryAvailable, RequestedInformation_AvaiableMemoryBuffer }; var outParams = vmMgmt.InvokeMethod(WMI_Method_GetSummaryInformation, inParams, null); if ((UInt32)outParams["ReturnValue"] == 0)//Completed { var summaryInfoList = (ManagementBaseObject[])outParams["SummaryInformation"]; var summaryInfo = summaryInfoList.FirstOrDefault(); data[KeyName_MemoryUsage] = summaryInfo[KeyName_MemoryUsage]; data[KeyName_MemoryAvailable] = summaryInfo[KeyName_MemoryAvailable]; data[KeyName_AvailableMemoryBuffer] = summaryInfo[KeyName_AvailableMemoryBuffer]; } else { throw new ManagementException(String.Format("Method {0} returns error:{1}", WMI_Method_GetSummaryInformation, (UInt32)outParams["ReturnValue"])); } } return(data); } }