Saturday, July 24, 2021

PowerCLI script to move specific hard disk to datastore

 PowerCLI script to move specific hard disk to datastore


Connect-VIServer vcenterserver

$input = Import-Csv C:\Temp\vmlist.csv

foreach ($row in $input)

{

    $VMName=$row.VMName

    $HDD=$row.HDD

    $DSName=$row.DSName

    Get-HardDisk -VM $VMName -Name $HDD | Move-HardDisk -Datastore $DSName -Confirm:$False -RunAsync

}

Disconnect-VIServer vcenterserver -Confirm:$false


<#

Content of vmlist.csv

VMName,HDD,DSName

vm1,Hard disk 4,DS1

vm2,Hard disk 2,DS2

vm3,Hard disk 5,DS3

#>

No comments:

Post a Comment