Move-VM

Hi.
I am planning on moving many VM’s to another Hyper-V host.
This should be pretty easy, since the vm’s are running on a cluster,
Here are the code.

Maybe I’m making it more difficult than it is.
Can you help me?

Hi Nicolai,

Are you saying the code is not working, or just asking for comments on if your code could be neater?

Hi Tim.
Sorry I confused you, the script was not working, but I made it harder than I should.
I have now managed to fix it.

Here is a script that Works!
#Migrating all vm’s to another host without storage.
#Useful when the storage is on a cluster volume
$SourceHost = “secretservername1”
$DestinationHost = “Secretservername2”
$VMsOnHost = Get-VM -ComputerName $SourceHost

foreach ($VM in $VMsOnHost){
Write-Host ("Moving "+$VM.Name)
Move-VM -ComputerName $SourceHost -Name $VM.Name -DestinationHost $DestinationHost
}

Ah, glad to see you got it working! Didn’t have a configuration i could test it on first to see.