如何使用 C# WMI 删除 hyper-v 虚拟机
How to delete hyper-v VM using C# WMI
我正在尝试使用 c# 和 WMI 自动执行 hyper-v 虚拟机操作。能够更改 VM 状态。现在我需要使用 C# 和 WMI 删除 VM,而 Msvm_ComputerSystem 只有一种方法 RequestStateChange。有什么方法可以在 VM 上执行此操作。
您需要使用 Msvm_VirtualSystemManagementService
class 的 DestroyVirtualSystem
方法。您可以查看它的 documentation or check out a sample script(它是在 VBScript 中,但您应该能够很容易地将它翻译成 C#)。
注意Hyper-V PowerShell cmdlets are incredibly rich and can be invoked with a PowerShell script or from C# - see example 1 and 。你也可以考虑使用它们。
我正在尝试使用 c# 和 WMI 自动执行 hyper-v 虚拟机操作。能够更改 VM 状态。现在我需要使用 C# 和 WMI 删除 VM,而 Msvm_ComputerSystem 只有一种方法 RequestStateChange。有什么方法可以在 VM 上执行此操作。
您需要使用 Msvm_VirtualSystemManagementService
class 的 DestroyVirtualSystem
方法。您可以查看它的 documentation or check out a sample script(它是在 VBScript 中,但您应该能够很容易地将它翻译成 C#)。
注意Hyper-V PowerShell cmdlets are incredibly rich and can be invoked with a PowerShell script or from C# - see example 1 and