Hi can someone help to finish this script for me please
I have two Vcenters on vSAN and I want to migrate VMs between the two.
When I do it manually it works so I know the VMotion is working however when I try to script this I get the following error
CSV file
########SCRIPT to Migrate using a CSV file ####################
#Variables
$sourceVC = 'SourceVC'
#Passwords are stored in secure encrypted file
$destVC = 'DestinationVC'
#Passwords are stored in secure encrypted file
# Connect to the vCenter Servers
$sourceVCConn = Connect-VIServer -Server $sourceVC -Credential (Import-Clixml -Path E:\temp\password\existingVCadminpass.xml)
$destVCConn = Connect-VIServer -Server $destVC -Credential (Import-Clixml -Path E:\temp\password\newVCadminpass.xml)
#Import List of VMs to be migrated (cross VC migration no linked mode required )
$VMS =Import-Csv -Path E:\temp\password\migratevmlist.csv
$vm = Get-VM -Name $vms.name -Server $sourceVCConn
$networkAdapter = Get-NetworkAdapter -VM $vm -Server $sourceVCConn
$destination = Get-VMHost -name $VMS.targethost -Server $destVCConn
$destinationPortGroup = Get-VirtualPortGroup -VirtualSwitch $VMS.targetswitchname -name $VMS.targetportgroup -VMHost $destination
$destinationDatastore = Get-Datastore -name $vms.targetdatastore -Server $destVCConn
#Migrate VM
Move-VM -VM $vm -Destination $destination -NetworkAdapter $networkAdapter -PortGroup $destinationPortGroup -Datastore $destinationDatastore
###############################################################################################################################
This is the error I get and it is triggered at the Move-vm statement
Move-VM : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.ViCore.Types.V1.Inventory.VIContainer' required by parameter 'Destination'. Specified
method is not supported.
At line:23 char:30
+ Move-VM -VM $vm -Destination $destination -NetworkAdapter $networkAda ...
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Move-VM], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM
Can someone help me please
From the message it looks as if there is more than 1 value in the $destination variable.
I'm not sure why you pass the complete CSV file ($vms), instead of looping row by row.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference