LucD
Leadership
Leadership

You want the ForEach loop to go through all the rows in the array (that you imported from the CSV file).

Try like this

$csvinput = Import-Csv -Path "C:\Powershell\CSV\Migrate.csv" -Header Name,PortGroup,DestinationPG,VMhost,DestinationVMhost,Datastore,DestinationDS,DrsGroup 

Foreach ($row in $csvinput){

   $vm = Get-VM -Name $row.Name

   $destinationEsx = Get-VMHost $row.DestinationVMhost

   $networkAdapter = Get-NetworkAdapter -VM $vm

   $detinationPortGroup = Get-VDPortgroup -VDSwitch 'vDS-Prod-01' -Name $row.DestinationPG

   $destinationDatastore = Get-Datastore $row.Datastore

   Move-VM -VM $VM -Destination $row.$destinationEsx -NetworkAdapter $networkAdapter -PortGroup $destinationPortGroup -Datastore $destinationDatastore -DiskStorageFormat Thin

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference