Somethimes you need to bulk migrate some Hyper-v virtual machines.
This is not possible with the VMM gui.
In this situation PowerShell can help:
Filter on VMname
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Import-Module virtualmachinemanager #Get Virtual machine with a specified name: $vm = Get-SCVirtualMachine | Where { $_.name -match "ROB" } #TargetPath Not required VM migration $path = "c:\clusterstorage\TargetLUN" #TargetHost Not required Storage migration $vmhost = "TargetHost" #Move Action foreach ($VMs in $VM){ #Creates a uniq job ID so you can monitor the status in VMM $JobGroupID = [Guid]::NewGuid().ToString() Move-SCVirtualMachine -VM $vms -VMHost $vmhost -Path $path -RunAsynchronously -JobGroup $JobGroupID } |
Replace the $VM line when you need to migrate all the machines placed on a specified host:
1 |
$vm = Get-SCVMHost | where { $_.Name -eq "VMHOST" } | get-scvirtualmachine |
With the Move-SCVirtualMachine you have the -JobGroupID. Do you know how we can use this to monitor the status of the job and tell when it is complete?
thanks,
tim
Yes sure, this can be done using the VirtualMachineManger PowerShell plugin.
I’ve made a sample script here: Monitor VMM Job Using PowerShell