0
votes

I am trying to automate hyper-v vm operations using c# and WMI. Able to change VM state. Now I need to delete VM using C# and WMI and Msvm_ComputerSystem has only one method RequestStateChange. Is there any way to perform this action on VM.

1

1 Answers

1
votes

You'll need to use the DestroyVirtualSystem method of the Msvm_VirtualSystemManagementService class. You can look at its documentation or check out a sample script (it's in VBScript but you should be able to translate it to C# fairly easily).

Note that the Hyper-V PowerShell cmdlets are incredibly rich and can be invoked with a PowerShell script or from C# - see example 1 and example 2. You can consider using them too.