VMware Cloud Community
mars0077
Enthusiast
Enthusiast
Jump to solution

PowerCLI script for migrating VMs from one ESX cluster using VSS to another using VDS.

Hi guys,

I'm hoping you guys can help me out on this one. We are looking to migrate a fair amount of virtual machines from one ESX cluster using a different SAN to another ESX cluster using a new SAN. Both of these clusters are managed by the same vCenter instance.  Cluster A is using a VDS and cluster B is using VSS and we would like to go from Cluster A to Cluster B.

I can easily perform this task by using the web client and performing a compute and storage migration. Using the web client also allows me to change the mapping of the source network (VSS) to the new destination network (DVS) without any errors or downtime. All preliminary compatibility checks pass with no errors.

Obviously I would like to automate this process but I am running into an error when using my script.  I manually connect to my vCenter instance hence no connection string is present. All virtual machines to be moved are stored inside the vms.txt file which is being read.

Here's the script:

$vms = Get-Content D:\Scripts\vms.txt

foreach ($vm in $vms)

{

#Move-VM -VM $vms -Destination 'oldesx' -Datastore 'newVMFS' -PortGroup 'newPG(VDS)'

}

Here's the error I am getting when I execute my script:

Move-VM : Cannot bind parameter 'PortGroup'. Cannot convert the "myvdsportgroup" value of type "System.String" to type

"VMware.VimAutomation.ViCore.Types.V1.Host.Networking.VirtualPortGroupBase".

At D:\Scripts\Global\vMotion\bulkmove.ps1:6 char:114

+ ... e 'newVMFS' -PortGroup ''myvdsportgroup"

+                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Move-VM], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

What do I need to include into my script to honor the portgroup change as part of the migration effort.

Thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Just did some further testing (on vSphere 6.5), and as far as I can tell changing the network connection from a VSS portgroup to a VDS portgroup works without a glitch for me.

I did something like this

Update: note that migrating from VSS to VDS this way is only supported since vSphere 6

$vmName = 'MyVM'

$newEsxName = 'MyEsx2'

$newDsName = 'MyDS2'

$newPgName = 'dvPortGroup'

$vm = Get-VM -Name $vmName

$esx = Get-VMHost -Name $newEsxName

$ds = Get-Datastore -Name $newDsName

$pg = Get-VDPortgroup -Name $newPgName

Move-VM -VM $vm -Destination $esx -Datastore $ds -PortGroup $pg


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

View solution in original post

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

Did you try by passing the actual portgroup object (returned by Get-VdPortgroup) instead of the name (as a string)?


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

Reply
0 Kudos
mars0077
Enthusiast
Enthusiast
Jump to solution

Yes, sir. I'm using the same exact values returned form the Get-VDPortgroup command-let. I even renamed the VDS portgroup to match the same name as the VSS portgroup and got the same error. I know this script would work if we are moving from VSS to VSS

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Just did some further testing (on vSphere 6.5), and as far as I can tell changing the network connection from a VSS portgroup to a VDS portgroup works without a glitch for me.

I did something like this

Update: note that migrating from VSS to VDS this way is only supported since vSphere 6

$vmName = 'MyVM'

$newEsxName = 'MyEsx2'

$newDsName = 'MyDS2'

$newPgName = 'dvPortGroup'

$vm = Get-VM -Name $vmName

$esx = Get-VMHost -Name $newEsxName

$ds = Get-Datastore -Name $newDsName

$pg = Get-VDPortgroup -Name $newPgName

Move-VM -VM $vm -Destination $esx -Datastore $ds -PortGroup $pg


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

Reply
0 Kudos
mars0077
Enthusiast
Enthusiast
Jump to solution

Sir,

Your code below worked flawlessly!! My mistake on not mentioning the vSphere platform early on. Yes, we are on vSphere 6.5. Thanks again!!

Reply
0 Kudos
gamecube
Contributor
Contributor
Jump to solution

LucD

I followed your script with my environment and got an error.

$vmName = 'JDCtest2012-clone'

$newEsxName = 'ujdcbpesx301.chn.mkcorp.com'

$newDsName = 'jdc-prod-scs-1'

$newPgName = 'BTS_GRN_PROD_BareMetalServers 10.194.24.0'

$vm = Get-VM -Name $vmName

$esx = Get-VMHost -Name $newEsxName

$ds = Get-Datastore -Name $newDsName

$pg = Get-VDPortgroup -Name $newPgName

Move-VM -VM $vm -Destination $esx -Datastore $ds -PortGroup $pg

Move-VM : A parameter cannot be found that matches parameter name 'PortGroup'.

At C:\Users\liuchri.admin\Desktop\migration test.ps1:11 char:60

+ Move-VM -VM $vm -Destination $esx -Datastore $ds -PortGroup <<<<  $pg

    + CategoryInfo          : InvalidArgument: (:) [Move-VM], ParameterBindingException

    + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

Could you please help to check the error?

Reply
0 Kudos
gamecube
Contributor
Contributor
Jump to solution

I have got the reason.

My powercli is 5.5. When I update to 6.0 the error gone.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Great to hear!


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

Reply
0 Kudos