What is the easiest way to storage vmotion a VM with PowerCLI?
Hi,
The easiest Way is Move-VM
Below is a small script that I put together to help me with some VM Migrations I had recently.
I got a lot of help with this from others on this forum so thanks to those guys.
The script takes a list of VM Names from a text file and migrates them randomly to DataStores of your choosing.
i.e
Hope this helps
$filelocation = Read-Host "Please enter the name of the target file, include the full path, E.g. c:\Temp\List.txt"
$VMs = get-vm (Get-Content $filelocation)
$storage = Get-Datastore | where {$_.name -match “Your_DataStore_Name_Goes_here"}
foreach ($v in $VMs) {
$random_Datastore_in_array = Get-Datastore -Name $storage.name | where {$_.freespacegb -GE ($v.provisionedspaceGB*1.20)} | Get-Random -Count 1
Write-Host "Storage vMotion of $v to $random_Datastore_in_array beginning"
Move-VM -VM $v -Datastore $random_Datastore_in_array -Confirm:$false
Get-VM $v | Get-Datastore |
select @{N="Date";E={(Get-Date).ToString()}},
@{N="VM";E={($v).Name}},
@{N="LUN";E={$random_Datastore_in_array.Name}},
@{N="FreeSpace (GB)";E={[math]::Round($random_Datastore_in_array.FreeSpaceGB)}} |
Export-Csv c:\Temp\Storage_migrations.csv -NoTypeInformation -Append
}
C:\Temp\Storage_migrations.csv
Hi...
simply Move-VM cmdlet: http://pubs.vmware.com/vsphere-60/index.jsp#com.vmware.powercli.cmdletref.doc/Move-VM.html and use datastore as destination
Regards
Hi,
The easiest Way is Move-VM
Below is a small script that I put together to help me with some VM Migrations I had recently.
I got a lot of help with this from others on this forum so thanks to those guys.
The script takes a list of VM Names from a text file and migrates them randomly to DataStores of your choosing.
i.e
Hope this helps
$filelocation = Read-Host "Please enter the name of the target file, include the full path, E.g. c:\Temp\List.txt"
$VMs = get-vm (Get-Content $filelocation)
$storage = Get-Datastore | where {$_.name -match “Your_DataStore_Name_Goes_here"}
foreach ($v in $VMs) {
$random_Datastore_in_array = Get-Datastore -Name $storage.name | where {$_.freespacegb -GE ($v.provisionedspaceGB*1.20)} | Get-Random -Count 1
Write-Host "Storage vMotion of $v to $random_Datastore_in_array beginning"
Move-VM -VM $v -Datastore $random_Datastore_in_array -Confirm:$false
Get-VM $v | Get-Datastore |
select @{N="Date";E={(Get-Date).ToString()}},
@{N="VM";E={($v).Name}},
@{N="LUN";E={$random_Datastore_in_array.Name}},
@{N="FreeSpace (GB)";E={[math]::Round($random_Datastore_in_array.FreeSpaceGB)}} |
Export-Csv c:\Temp\Storage_migrations.csv -NoTypeInformation -Append
}
C:\Temp\Storage_migrations.csv
OK great - thanks!