Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. # My Login Credentials
  2.  
  3. $vi_server = "X.X.X.X" # Set to your vCenter hostname|IP
  4.  
  5. $vcuser = "MyLogin@vsphere.local" # Set to your vCenter username to connect
  6.  
  7. $vcpass = "VerySecurePassword123" # Set to your vCenter username password to connect
  8.  
  9.  
  10.  
  11. # Connect to vCenter
  12.  
  13. Connect-VIServer -Server $vi_server -User $vcuser -Password $vcpass
  14.  
  15.  
  16. # I want all old and new datastores as objects in arrays
  17.  
  18. $OldDatastores = Get-Datastore TEST-01
  19. $NewDatastores = Get-Datastore TEST-02
  20. $i = 0
  21.  
  22.  
  23.  
  24. # Get all VMs in each old datastore and move them
  25.  
  26. Foreach ($OldDatastore in $OldDatastores){
  27. $VMs = Get-VM -Datastore $OldDatastore
  28.  
  29. Foreach ($VM in $VMs)
  30. {
  31. # Move the VM to a new datastore
  32. $VM | Move-VM -Datastore $NewDatastores[$i] -RunAsync
  33.  
  34.  
  35. }
  36.  
  37. $i++
  38.  
  39. # Wait timer for next migrations
  40.  
  41. Start-Sleep 5
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement