Jump to content

Recommended Posts

Hello everyone Just wondering if anyone has ventured into Backing up Hyper-V Vm machines.

I'm wanting to shutdown the VM.. Check its status via Ping or a response from the Hyper-V manager that its fully off and then do a copy to a network drive. Finish the copy and start the machine back up..

Now the status, Shutdown and Startup is my main challenge. Any susgesstions ?? Trying to keep it as simple as possible. I will add some loggin , email functionality etc..

Dim $WMIService
Dim $VMList
Dim $VMGuid
Dim $ShutdownList
Dim $Result
$VMName = "VM2011"
_ShutdownVM($VMName)
Func _ShutdownVM($VMName)
$WMIService = ObjGet("winmgmts:\\.\root\virtualization")
$VMList = $WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem WHERE ElementName='" & $VMName & "'")
$VMGuid = $VMList.ItemIndex(0).Name
MsgBox(0, "VM GUID", $VMGuid)
$ShutdownList = $WMIService.ExecQuery("SELECT * FROM Msvm_ShutdownComponent WHERE SystemName='" & $VMGuid & "'")
$Result = $ShutdownList.ItemIndex(0).InitiateShutdown(True, "Because I said so")
EndFunc   ;==>_ShutdownVM
Func _StartupVM($VMName)
$WMIService = ObjGet("winmgmts:\\.\root\virtualization")
$VMList = $WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem WHERE ElementName='" & $VMName & "'")
; Request a state change on the first VM that is returned' 2 = start, 3 = stop and 32769 = save state
$VMList.ItemIndex(0).RequestStateChange(2)
EndFunc   ;==>_StartupVM
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...