1 2 Previous Next 27 Replies Latest reply on Jan 28, 2020 5:53 AM by LucD

    VMware HCX migration  using powerCLI

    Vel_VMware Enthusiast

      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

        • 1. Re: VMware HCX migration  using powerCLI
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          And which error do you get?

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: VMware HCX migration  using powerCLI
            Vel_VMware Enthusiast

            New-HCXMigration : Cannot bind parameter 'DestinationSite'. Cannot convert the

            "10.159.170.103" value of type "System.String" to type "VMware.VimAutomation.Hc

            x.Types.V1.HCXSite".

            At C:\MigratioN.Ps1:12 char:51

            + $newMigration = New-HCXMigration -DestinationSite $DestSite -DiskProv ...

            +                                                   ~~~~~~~~~

                + CategoryInfo          : InvalidArgument: (:) [New-HCXMigration], Paramet

               erBindingException

                + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomat

               ion.Hcx.Commands.Cmdlets.NewHCXMigration

             

             

            Test-HCXMigration : Cannot bind argument to parameter 'Migration' because it is

            null.

            At C:\MigratioN.Ps1:.Ps1:13 char:30

            + Test-HCXMigration -Migration $newMigration

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

                + CategoryInfo          : InvalidData: (:) [Test-HCXMigration], ParameterB

               indingValidationException

                + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,V

               Mware.VimAutomation.Hcx.Commands.Cmdlets.TestHCXMigration

            • 3. Re: VMware HCX migration  using powerCLI
              LucD Guru
              Community WarriorsUser ModeratorsvExpert

              The value on the Destination parameter needs to be an object returned by Get-HCXSite, not a string.

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: VMware HCX migration  using powerCLI
                Vel_VMware Enthusiast

                I am not getting, can you please help me explaining bit more

                • 5. Re: VMware HCX migration  using powerCLI
                  LucD Guru
                  Community WarriorsUser ModeratorsvExpert

                  Something like this

                   

                  $dest = Get-HCXSite -Name $DestSite

                  $newMigration = New-HCXMigration -DestinationSite $dest -DiskProvisionType Thick -Folder $DestFolder -MigrationType Bulk -SourceSite

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: VMware HCX migration  using powerCLI
                    Vel_VMware Enthusiast

                    Hi LuCD,

                     

                    Sorry to late to be back on this. I was trying to create the PowerCLI script to automate VMware HCX migration.. Unfortunately I couldn't do it successfully.

                     

                    Can you help me with the script to automate the VMware HCX migration.

                     

                    Thanks in advance.

                    • 7. Re: VMware HCX migration  using powerCLI
                      LucD Guru
                      vExpertUser ModeratorsCommunity Warriors

                      I'm afraid I don't have access to HCX hardware, so I can't really test anything.

                       

                      Are you still getting the same error?

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: VMware HCX migration  using powerCLI
                        Vel_VMware Enthusiast

                        Hi LuCD.

                         

                         

                        Yeah, Some how am unable to fix this.. Also, I want to add few more feature also Which I really don't know how to do it.

                        • 9. Re: VMware HCX migration  using powerCLI
                          Vel_VMware Enthusiast

                          Hi LuCD,

                           

                          If I give you the drafted code, is it possible for you to bug it if anything.

                           

                           

                          Thanks in advance.

                          • 10. Re: VMware HCX migration  using powerCLI
                            LucD Guru
                            User ModeratorsvExpertCommunity Warriors

                            I can have a look at it, but without the specific HW it will be difficult to diagnose runtime errors.

                            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                            • 11. Re: VMware HCX migration  using powerCLI
                              Vel_VMware Enthusiast

                              Hi LuCD,

                               

                              Good Day...!

                               

                              I have created script and it works fine also.. Need your help to fine tune the script.

                               

                              1) I want to create input popup to ask the HCX Server name since I entered the it directly in the script.

                              2) Create condition to show connection successful message only if connect established successfully.

                              3) Multiple network mapping upto 5 networks. Below script has only one network to map. If VM's has below 5 networks, script has to ignore and run rest of the network mapping.

                              4) You could New-HCXMigration will have the input for CSV file. So CSV file will have 100's of VM's. Test-HCXMigration performs subsequently and its moving to next server once migration initiated for previous server. This is taking too much time. Want to optimize it like Test-HCXMigration has to be done for all servers  and it has to generate the result report and save it in a path. Then, it has to initiate the Start-HCXMigration for all servers.

                               

                               

                              ######## Script######

                               

                              $Name= $Env:Username

                              $Cre = Get-Credential -Message "!!! Greetings $Name !!!"

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

                              $Server = "HCXServer"

                              $Newmigration = @()

                              Write-Host "Connecting to HCXServer:" $Server"..."

                              Connect-HCXServer -server $server -credential $Cre

                              Write-Host "Connection to HCXServer: "$Server" has been extablished successfully."

                              $Data | foreach {

                              $VmHost = $_.ServerName

                              $SourceSite = $_.SourceSite

                              $SourceNetwork = $_.SourceNetwork

                              $DestSite = $_.DestinationSite

                              $DestFolder = $_.containerFolder

                              $DestinationCompute = $_.DestinationCompute

                              $Datastore = $_.DestinationDataStore

                              $DestNetwork = $_.DestinationNetwork

                              $InitiateTime = $_.ScheduleStartTime

                              $CompleteTime = $_.ScheduleEndTime

                               

                               

                              write-host("Getting Time for Scheduling")

                              $StartTime = Get-Date $InitiateTime

                              $EndTime = Get-Date $CompleteTime

                              $SrcSite = Get-HCXSite -Source $SourceSite

                              $DstSite = Get-HCXSite -Destination $DestSite

                              $vm = Get-HCXVM -Name $VmHost -Site $SrcSite

                              $TargetCluster = Get-HCXContainer -Name $DestinationCompute -Site $DstSite

                              $TargetFolder = Get-HCXContainer -Name $DestFolder -Site $DstSite

                              $TargetDatastore = Get-HCXDatastore -Name $Datastore -Site $DstSite

                               

                               

                              $SrcNetwork = Get-HCXNetwork -Name $SourceNetwork -type DistributedVirtualPortgroup -Site $SrcSite

                              $DstNetwork = Get-HCXNetwork -Name $DestNetwork -type DistributedVirtualPortgroup -Site $DstSite

                              $TarNetwork = New-HCXNetworkMapping -SourceNetwork $SrcNetwork -DestinationNetwork $DstNetwork

                               

                               

                               

                               

                              #####Intiating Miration

                              ForEach($HCXVM in $vm)

                              {

                              Write-host("Adding workloads for migration...")

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

                              Test-HCXMigration -Migration $newMigration | Export-CSV T:\Script\MigrationStatus.csv -NoTypeInformation -UseCulture

                              #$TestResult | Export-CSV T:\Script\MigrationTestResult.csv -NoTypeInformation -UseCulture

                              Start-HCXMigration -Migration $newMigration -Confirm:$true

                              }

                              #$MigrationStatus = Get-HCXMigration `| Format-List | Export-CSV T:\Script\MigrationStatus.csv -NoTypeInformation -UseCulture

                              #Write-host("Status report generated")

                              }

                              • 12. Re: VMware HCX migration  using powerCLI
                                LucD Guru
                                Community WarriorsvExpertUser Moderators

                                1. You could use a Read-Host, like this

                                 

                                          $Server = Read-Host  -Prompt 'Enter HCX Server'

                                 

                                2. You could use a try-catch

                                 

                                try{

                                    Connect-HCXServer -server $server -credential $Cre -ErrorAction Stop

                                }

                                catch {

                                    throw "Connection to $Server failed!"

                                }

                                 

                                3. Not sure what you mean here.

                                4. You would still need a Test-HcxMigration call before eventually doing a Start-HcxMigration. I would suggest to only try a migration when the test returns success in ValidationResult.Type. If you want to run migrations in parallel, you would need to look at background jobs (with Start-Job).

                                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                • 13. Re: VMware HCX migration  using powerCLI
                                  Vel_VMware Enthusiast

                                  above script has capable to map only one target network and it defined as well New-HCXNetworkMapping. Few VM's has more than a NIC's and Portgroups, so how can I make the script to map multiple target portgroups with respective source portgroups.

                                  • 14. Re: VMware HCX migration  using powerCLI
                                    Vel_VMware Enthusiast

                                    No, I don't want to start the migration in parallel while validation happens. Normally this script executes and adds the servers one by one, validating and migrating.  To more clear, It takes one VM, testing it and initiating migration, then second VM, testing it  and initiation migration and then third VM's. This  is really very tedious to check the validation error in screen. So, want to run test validation first for entire servers in list and it will generate validation results. This result has to save in a path in CSV format with error and warnings. Once I had fix the error/Warnings from the validation result, let me run the script again and validation get succeeds and then migration starts.

                                    1 2 Previous Next