Move-VM

This topic contains 3 replies, has 2 voices, and was last updated by  Tim Pringle 1 year, 7 months ago.

  • Author
    Posts
  • #33688

    Nicolai Magnussen
    Participant

    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?

  • #33760

    Tim Pringle
    Participant

    Hi Nicolai,

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

  • #33763

    Nicolai Magnussen
    Participant

    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
    }

  • #33764

    Tim Pringle
    Participant

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

You must be logged in to reply to this topic.