Im looking to svMotion VM's based on a spreadsheet or txt file (either will work for me) from one datastore to another. I've found simple ones that do it, but nothing that will import a csv file or txt file and svmotion those VM's.
Getting this error when i run the script
Move-VM : Cannot convert 'System.Object[]' to the type
'VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.StorageResource'
required by parameter 'Datastore'. Specified method is not supported.
At C:\Temp\VMListscript.ps1:41 char:34
+ $vmobj | move-vm -datastore $ds -runasync -confirm:$false
+ ~~~
+ CategoryInfo : InvalidArgument: (:) [Move-VM], ParameterBinding
Exception
+ FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCor
e.Cmdlets.Commands.MoveVM
That seems to indicate that $ds contains more than 1 object.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
HI Lucd,
Thank you for your quick reply, below is how our CSV looks, list of VM's all being migrated to same Datastore, and we are getting the above error
2XXXX-VM,SAN05-FC7
alXX-XXXVM,SAN05-FC7
alXX-XXXXXVM,SAN05-FC7
The error states that it sees an Object[] on the Datastore parameter.
That would mean that the Get-DatastoreCluster returns more than 1 object.
Are you perhaps connected to multiple vCenter?
Check what is in $globa;defaultVIServers.
And check what is in $ds
$ds = get-datastorecluster $row.destds
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
when i run the get-datastore command, i am getting this output, seems like Datastore is shared
Get-datastore SAN05-FC7
Name FreeSpaceGB CapacityGB
---- ----------- ----------
SAN05-FC7 16,002.122 65,535.750
SAN05-FC7 16,002.055 65,535.750
SAN05-FC7 16,002.104 65,535.750
You will have to pick one.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It worked now ,changed the below lines and added an additional row for esxhost for each vm
$ds = get-vmhost $row.esxname | Get-Datastore $row.destds
$vmobj | move-vm -datastore $ds -runasync -confirm:$false
There was also an issue with running script with vmotion limit, it got fixed while changing the Description -match to 'Relocate virtual machine'
Thank you Lucd for your inputs, it helped fixing the issue