如标题所示,我目前无法在 VBScript 中使用 WMI 查询检索虚拟机列表。Hyper-V 管理器正确识别有问题的主机上的 3 个虚拟机,但是当我查询 WMI 时,我只看到主机本身。
这是一个示例 VBScript(由 WMI Code Creator 提供):
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\virtualization\v2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Msvm_ComputerSystem instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "ElementName: " & objItem.ElementName
Next
输出:
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
-----------------------------------
Msvm_ComputerSystem instance
-----------------------------------
Description: Microsoft Hosting Computer System
ElementName: TEST-VH
非常感谢您的想法,建议或岩石,谢谢!