Powercli随笔 - PowerCLI script to sequentially Storage vMotion VMs from a CSV File

Posted martin001

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Powercli随笔 - PowerCLI script to sequentially Storage vMotion VMs from a CSV File相关的知识,希望对你有一定的参考价值。

PowerCLI script to sequentially Storage vMotion VMs from a CSV File

This is a PowerCLI script that I use to Storage vMotion (s/vmotion) VMs from an input file (CSV File). This helps me evacuate VMs from a datastore that will be decommissioned and this serves like an automation. With this, I do not have to log back to vCenter and manually do storage migrations. This also have a lesser performance impact compared to simultaneously queuing storage migrations manually in case this will be done on non-peak hours.

1
2
3
4
5
6
7
8
$VMsToRelocate = Import-Csv "ListOfVMsToRelocate.csv"
$Datastore = Get-Datastore -Name "datastore_name"
foreach ($VM in $VMsToRelocate)
{
Write-Host "Relocating VM:" $VM.Name "to" $Datastore
Get-VM -Name $VM.Name | Move-VM -datastore $Datastore > $null
}
Write-Host "Completed!"

Note that the CSV file must have a Header called Name, below is an example.

1
2
3
4
Name
VM1
VM2
VM3

If you want to export the list of VMs that you want to migrate, you can use RV Tools to generate a VM Inventory, export the list to MS Excel, do your filtering there (such as filter by the storage path), and I personally like to sort them by used size (in MB), then simply copy-paste to the CSV file. You do not need to create the CSV file in Excel, I use Notepad++.

以上是关于Powercli随笔 - PowerCLI script to sequentially Storage vMotion VMs from a CSV File的主要内容,如果未能解决你的问题,请参考以下文章

PowerCLi 管理VMware vCenter 批量部署导出导入

PowerCLi 导入 LicenseKey 到esxi

PowerCLi 管理VMware vCenter 一键批量部署OVA

PowerCLi 添加esxi主机到vCenter

PowerCLi 添加esxi主机到vCenter

PowerCLi 管理VMware vCenter 批量部署导出导入