1 2 3 Previous Next 90 Replies Latest reply on Mar 24, 2017 6:21 AM by sjuanlu

    Script to migrate cluster from one vCenter to another vCenter

    mark.chuman Hot Shot

      Attached is a script I use to migrate an ESXi cluster from one vCenter to another.  I'll be updating the script (will add VM folder locations and attributes, more qa, root credential storage - PASSWORD IS STORED IN TRANSCRIPT FILE - so, adjust this in script or cleanse transcript after run), but for now it handles HA settings, DRS settings, EVC, DRS vm rules (affinity/anti), folder import/export, permissions (datacenter, cluster, host, folder and vm) and maybe some other things I left out.  Does not deal with dvs as we use local vswitches.

       

      You'll need two VCs and a cluster you want to migrate.  The script does not create the datacenter in the destination VC, but it will create the cluster, disconnect, remove an add the hosts.

       

      I hope it can help someone as I've mainly been on the receiving end with regards to help from this forum .  Special note to Luc for a lot of the items in the script (folder functions, splat etc ).

       

      Just unzip to a directory and run with powercli (requested credentials must have VC privs to disconnect hosts etc.).

       

      As always with offerings, use at your own risk!

       

      *Using to go from 5.0 to 5.5.

        • 2. Re: Script to migrate cluster from one vCenter to another vCenter
          munishpalmakhija Enthusiast vExpert

          Thanks for sharing wonderful script , I have a similar requirement hope we can work together to achieve this

          Here is the detailed requirement

           

          We have shared pool of ESXi Servers which we use for many customers (we provide DR as a Service using SRM )

          We have dedicated vCenter and SRM Server for each and every customer

           

          Currently we have to manually remove/configure when we move around servers between customer

          I would want to write script to perform following steps

          • Disconnect ESXi from vCenter1
          • Create new ESXi Management Port Group
          • Modify the DNS Name for ESXi (Probably using CSV File, Assumption DNS entries are present already)
          • Remove existing VM Network Port Groups
          • Remove the exisiting ESXi Management Port Group
          • Connect ESXi to vCenter 2 using new ESXi Management Port Group (using DNS or IP )
          • Apply Host Profiles with Port Group Details or Create Port Groups Manually using csv file
          • Add host to existing cluster
          • 3. Re: Script to migrate cluster from one vCenter to another vCenter
            Madmax01 Hot Shot

            Hello,

             

            until now i used the InventorySnapshot from the Vmware Labs.  and was working very well so far. also with 5.1 > 5.5.

             

            Will have a look to the script. Idea behind is very very interesting. Everybody knows the big effort in the Back once migrating to new vCenter. theirefore i don't understand why vmware don't deliver an official Solution. Shouldn't be such a hard progress for them.

             

            Best regards

             

            Max

            • 4. Re: Script to migrate cluster from one vCenter to another vCenter
              mark.chuman Hot Shot

              Thanks.  The script has been working well for us so far.  I am working on adding in host profiles, but am not sure yet about the differences between host profile usage in 5.1 vs 5.5.  You want to just change the name of the ESX server, not the actual DNS record for the ESX server correct?

              • 5. Re: Script to migrate cluster from one vCenter to another vCenter
                mark.chuman Hot Shot

                Completely agree about VMware formally supporting a migration tool.  I tried to start as well with the inventorysnapshot tool, which is awesome, but I would randomly hit errors in the script during migrations and it took a lot of work to figure out what exactly was going wrong.  I was very interested in understanding exactly what's going on at any point during the script run and I just couldn't get that with the vmware labs provided script.  I'm currently working on an audit script that will check around 40 or 50 configuration details within our vCenter servers.  We'll probably dump it to Splunk to incorporate with our other vCenter related trending data.

                • 6. Re: Script to migrate cluster from one vCenter to another vCenter
                  JohnMcKeown Novice

                  Very nice script. Just tested 5.1 to 5.5 worked as stated.

                   

                  Only negative is that it didn't import the resource pools. But did take a huge amount of work out of the migration.   

                   

                  Oh forgot to add, the root password read host didnt seem to work so manually edited the script with a default on.

                  • 7. Re: Script to migrate cluster from one vCenter to another vCenter
                    mark.chuman Hot Shot


                    Really glad it helped John.  I've got a new version which I'll upload soon after I "sanitize" it for public use.

                    • 8. Re: Script to migrate cluster from one vCenter to another vCenter
                      mark.chuman Hot Shot

                      Here is the latest version.  Not exactly sure what's different from the one I originally posted, but there are some new items.  Here are some notes.

                       

                      Notes on script:

                       

                       

                      - Handles root password more securely.

                       

                       

                       

                      - There are pauses in the script.  Just adjust the seconds in those sections or comment out all together if you don't want pauses.

                       

                       

                       

                      - No more errors at empty DRS rules.

                       

                       

                       

                      - This part renames the old cluster.  I have it currently commented out.  Customize and uncomment to use:

                       

                      Set-Cluster -Cluster $Cluster -Name $Cluster" - Migrated to https://newvcenter.company.com/" -Confirm:$false

                       

                       

                       

                      - This part emails out reporting on migration activities.  I have it currently commented out.  Customize and uncomment to use:

                       

                      $CSVhosts = Import-Csv .\$SourcevCenter\$Cluster\VMHost.csv | out-string

                      Send-MailMessage -To "SOMEONE <SOMEONE@SOMEWHERE.com>", "SOMEONE2 <SOMEONE2@SOMEWHERE.com>" `

                      -From "ME <ME@SOMEWHERE.com>" -subject "Notice - ESXi Servers Migrated" `

                      -smtp smtp.server.com -body "$CSVhosts Source vCenter $SourcevCenter

                      Destination vCenter $DestinationvCenter" | out-null

                      • 9. Re: Script to migrate cluster from one vCenter to another vCenter
                        kiraa Enthusiast

                        Great script.

                         

                        I have not used this in a production environment but have used in a lab and it works well.

                         

                        Jake

                        • 10. Re: Script to migrate cluster from one vCenter to another vCenter
                          mark.chuman Hot Shot

                          Glad you like it.  Try the new version (attached).  Working towards trying to have it fully automated (ie, no user input), but this version hits a csv with the information, so you only have to enter credentials once and it will cycle through the different clusters in the CVS.  FYI, I've used it multiple times in production.

                          • 11. Re: Script to migrate cluster from one vCenter to another vCenter
                            iliketurbos Enthusiast

                            nice script but I don't see where it does any resources pool yet. for it to be totally useful that would be required.

                             

                            but a great start so far!

                            • 12. Re: Script to migrate cluster from one vCenter to another vCenter
                              rnotaro Novice

                              Trying to run this script and I'm getting this error

                               

                              Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null, empty, or an element of the argument collection contains a null value.

                              Supply a collection that does not contain any null values and then try the command again.

                              At C:\vcenter_migration\Functions\get_folder_path_function.ps1:46 char:25

                              +         $fld = Get-View $fld.Parent

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

                                  + CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingValidationException

                                  + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

                               

                              This happens right after it tried to export folders.  Any ideas?

                              • 13. Re: Script to migrate cluster from one vCenter to another vCenter
                                mark.chuman Hot Shot

                                Can you upload the transcript file? - Look it over first as it may contain some of your company data etc.

                                • 14. Re: Script to migrate cluster from one vCenter to another vCenter
                                  rnotaro Novice

                                  **********************

                                  Windows PowerShell transcript start

                                  Start time: 20150122154328

                                  Username  : XXXXXXXX

                                  Machine  : XXXXXXXx (Microsoft Windows NT 6.1.7601 Service Pack 1)

                                  **********************

                                   

                                  Please confirm your information before proceeding

                                   

                                  Target cluster         - XXXXX

                                  Source vCenter         - XXXXXXSource Datacenter      - XXXXXXX

                                  Destination vCenter    - XXXXXX

                                  Destination datacenter - XXXXXXX

                                  Please confirm that the above information is correct and press any key to continue . . . 

                                   

                                  Running QA tests against the information provided

                                  Cluster XXXXX DOES exist in XXXXXXX

                                   

                                  Checking connection to the ESX hosts with the root password provided

                                   

                                  Datacenter XXXXXX DOES exist in XXXXXX

                                  1

                                   

                                  Exporting folders in source datacenter XXXXXXX

                                   

                                   

                                   

                                  Action to take for this exception:

                                  Cannot validate argument on parameter 'VIObject'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a

                                  collection that does not contain any null values and then try the command again.

                                  [C] Continue  [I] Silently Continue  [B] Break  [S] Suspend  [?] Help (default is "C"): c

                                  Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null, empty, or an element of the argument collection contains a null value.

                                  Supply a collection that does not contain any null values and then try the command again.

                                  At C:\vcenter_migration\Functions\get_folder_path_function.ps1:46 char:25

                                  +         $fld = Get-View $fld.Parent

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

                                      + CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingValidationException

                                      + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

                                   

                                   

                                   

                                  Action to take for this exception:

                                  Cannot validate argument on parameter 'VIObject'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a

                                  collection that does not contain any null values and then try the command again.

                                  [C] Continue  [I] Silently Continue  [B] Break  [S] Suspend  [?] Help (default is "C"): c

                                  Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null, empty, or an element of the argument collection contains a null value.

                                  Supply a collection that does not contain any null values and then try the command again.

                                  At C:\vcenter_migration\Functions\get_folder_path_function.ps1:46 char:25

                                  +         $fld = Get-View $fld.Parent

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

                                      + CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingValidationException

                                      + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

                                   

                                   

                                   

                                  Action to take for this exception:

                                  Cannot validate argument on parameter 'VIObject'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a

                                  collection that does not contain any null values and then try the command again.

                                  [C] Continue  [I] Silently Continue  [B] Break  [S] Suspend  [?] Help (default is "C"): b

                                   

                                   

                                  Action to take for this exception:

                                  Cannot validate argument on parameter 'VIObject'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a

                                  collection that does not contain any null values and then try the command again.

                                  [C] Continue  [I] Silently Continue  [B] Break  [S] Suspend  [?] Help (default is "C"): b

                                  % : Cannot validate argument on parameter 'VIObject'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a

                                  collection that does not contain any null values and then try the command again.

                                  At C:\vcenter_migration\Functions\get_folder_path_function.ps1:38 char:15

                                  +     $Folder | %{

                                  +               ~~

                                      + CategoryInfo          : InvalidData: (:) [ForEach-Object], ParameterBindingValidationException

                                      + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ForEachObjectCommand

                                   

                                  PowerCLI C:\vcenter_migration>

                                  1 2 3 Previous Next