VMware Cloud Community
justinsmith
Enthusiast
Enthusiast
Jump to solution

PowerCLI script to svMotion VM's based on a list of VM's

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.

0 Kudos
46 Replies
Partheepan
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That seems to indicate that $ds contains more than 1 object.


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

0 Kudos
Partheepan
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
Partheepan
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You will have to pick one.


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

0 Kudos
Partheepan
Contributor
Contributor
Jump to solution

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

0 Kudos