VMware Cloud Community
Vel_VMware
Enthusiast
Enthusiast

VMware HCX migration using powerCLI

Hi

Can anyone help me to check the below script is anything wrong in it.. I am getting error while running. This is for VMware HCX migration powerCLI script.

I tried to initiate migration by using this script and but getting error.

$Data = Import-csv C:\Input.csv -delimiter “;”

$Data | foreach {

$VmHost = $_.ServerName

$SourceSite = $_.SourceSite

$DestSite = $_.DestinationSite

$DestFolder = $_.containerFolder

$DestinationCompute = $_.DestinationCompute

$Datastore = $_.DestinationDataStore

$Network = $_.DestinationNetwork

#####Intiating Miration

$newMigration = New-HCXMigration -DestinationSite $DestSite -DiskProvisionType Thick -Folder $DestFolder -MigrationType Bulk -SourceSite $SourceSite -TargetComputeContainer $DestinationCompute -TargetDatastore $Datastore -TargetNetwork $Network -VM $VmHost

Test-HCXMigration -Migration $newMigration

#Start-HCXMigration -Migration $newMigration -Confirm:$false

}

Thanks in advance

0 Kudos
27 Replies
LucD
Leadership
Leadership

It looks like $SrcNetworkB is an array, while the New-HcxNetworkMapping cmdlet only accepts a single value on the SourceNetwork parameter.

If Get-HcxNetwork returns more than one object, you will have to a use a ForEach loop over all the returned networks.


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

0 Kudos
Vel_VMware
Enthusiast
Enthusiast

Can you help me with the changes please also if networkB, C and D data is not available in the sheet, it shouldn't return any errors in screen.

Can we export the whole list migration status report in CSV once script ends.

0 Kudos
LucD
Leadership
Leadership

Like I said before, I don't have access to HCX HW, so I can't really test this.


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

0 Kudos
Vel_VMware
Enthusiast
Enthusiast

ok LuCD Thank you..

0 Kudos
Vel_VMware
Enthusiast
Enthusiast

Hi LuCD

Could you guss why I am getting the below errror,

Import-Csv : A positional parameter cannot be found that accepts argument '\MappingInput.csv'.

At T:\Migration initiation.ps1:2 char:9

+ $Data = Import-csv -Path T:\MappingInput.csv -delimiter ";"

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

    + CategoryInfo          : InvalidArgument: (:) [Import-Csv], ParameterBindingException

    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.ImportCsvCommand

And my code is,

$Name= $Env:Username

$Data = Import-csv T:\MappingInput.csv -delimiter “;”

0 Kudos
LucD
Leadership
Leadership

Place the path between single quotes.

$Data = Import-csv -Path 'T:\MappingInput.csv' -delimiter ';'


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

Vel_VMware
Enthusiast
Enthusiast

Hi LuCD,

I am unable to call multiple variable in -TargetNetwork.. How do I do that. I created as below

$newMigration = New-HCXMigration -SourceSite $SrcSite -DestinationSite $DstSite -VM $vm -MigrationType Bulk -DiskProvisionType Thick -TargetComputeContainer $TargetCluster -TargetDatastore $TargetDatastore -NetworkMapping {$TarNetworkA, $TarNetworkB, $TarNetworkC, $TarNetworkD} -UpgradeVMTools $False -RemoveISOs $True -ForcePowerOffVm $False -RetainMac $True -UpgradeHardware $False -RemoveSnapshots $False -ScheduleStartTime $StartTime -ScheduleEndTime $EndTime

0 Kudos
LucD
Leadership
Leadership

The NetworkMapping value should be an array afaik.

Try with -NetworkMapping @($TarNetworkA, $TarNetworkB, $TarNetworkC, $TarNetworkD)


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