2 Replies Latest reply on Sep 11, 2019 7:19 AM by Scotslad007

    Script for Storage vMotion from one datastore to another - 10 at a time

    rjmend Lurker

      Hello,

       

      Ive done some searching and could not find what I'm looking for so I am making a post: I would like to storage vMotion from one datastore to another, 10 at a time, and output the vm's migrated to a log file. I have this script so far that I have edited. Please let me know how to add the instructions on how to append to a log file and also 10 at a time. the -RunAsync also will not let me migrate one at a time so I may have to remove that as well. Any help?

       

      # My Login Credentials

       

       

      $vi_server = "X.X.X.X" # vCenter IP

       

       

      $vcuser = "MyLogin@vsphere.local" # My Username

       

      $vcpass = "VerySecurePassword123" # My Password

       

       

       

      # Connect to vCenter

       

      Connect-VIServer -Server $vi_server -User $vcuser -Password $vcpass

       

       

       

       

      # Old datastore and new datastore

       

       

      $OldDatastores = Get-Datastore TEST-01

      $NewDatastores = Get-Datastore TEST-02

      $i = 0

       

       

       

       

       

      # Get all VMs in each old datastore and move them

       

       

      Foreach ($OldDatastore in $OldDatastores){

          $VMs = Get-VM -Datastore $OldDatastore

       

       

          Foreach ($VM in $VMs)

          {

      # Move the VM to a new datastore

      $VM | Move-VM -Datastore $NewDatastores[$i] -RunAsync

       

       

       

          }

       

       

          $i++

       

       

          # Wait timer for next migrations

       

       

          Start-Sleep 5

       

       

      }