PowerCLI

 View Only
Expand all | Collapse all

Script to migrate cluster from one vCenter to another vCenter

LucD

LucDJul 13, 2014 08:15 AM

  • 1.  Script to migrate cluster from one vCenter to another vCenter

    Posted Jul 12, 2014 07:40 PM

    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 :smileyhappy:.  Special note to Luc for a lot of the items in the script (folder functions, splat etc :smileyhappy:).

    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

    Posted Jul 13, 2014 08:15 AM

    Great, thanks for sharing.



  • 3.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Aug 07, 2014 12:19 AM

    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


  • 4.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Aug 07, 2014 12:35 PM

    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

    Posted Aug 07, 2014 05:44 AM

    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



  • 6.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Aug 07, 2014 12:38 PM

    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.



  • 7.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Sep 17, 2014 02:08 PM

    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.



  • 8.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Sep 17, 2014 02:15 PM


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



  • 9.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Sep 26, 2014 07:10 PM

    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



  • 10.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Nov 03, 2014 03:11 AM

    Great script.

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

    Jake



  • 11.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Nov 03, 2014 01:47 PM

    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.



  • 12.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Dec 28, 2014 04:57 PM

    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!



  • 13.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 22, 2015 08:27 PM

    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?



  • 14.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 22, 2015 08:39 PM

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



  • 15.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 22, 2015 08:51 PM

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

    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>



  • 16.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 27, 2015 08:22 PM

    Can you try to run the latest version - attached to my latest reply today.



  • 17.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 27, 2015 08:30 PM

    It’ll be next week before I can try, but I’m going to do a few host. I’ll be doing over 6000 vms soon so I’ll be sure to let you know :smileyhappy:

    Thanks!



  • 18.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 27, 2015 07:21 PM

    Mark, do you have any updates for your script since you last  uploaded on 11/3?



  • 19.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 27, 2015 08:19 PM

    Attached is the latest version.  Can't remember exactly what's been added, but I do know, notes, attributes, folder permissions etc were added.  Just ran it in the lab and it ran fine. Also, have used it on 500+ hosts in production.

    NOTES:

    - Adjust the name of the vCenter if needed:

    Set-Cluster -Cluster $Cluster -Name $Cluster" - Migrated to https://New_vCenter_WebAddress_Here/" -Confirm:$false

    - Un comment this portion and enter your data to send an email notification at end of migration:

    #Notify others of migration activities

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

    #Send-MailMessage -To "SOMEONE1 <someone1@somewhere.com>", "SOMEONE2 <SOMEONE2@fmr.com>" `

    #-From "SENDER <SENDER@somewhere.com>" -subject "Notice - ESXi Servers Migrated" `

    #-smtp smtp.fmr.com -body "$CSVhosts Source vCenter $SourcevCenter

    #Destination vCenter $DestinationvCenter" | out-null

    -Script no longer creates cluster in new location with EVC settings.  EVC settings are exported, but not imported.  We ran into majore issues trying to migrate over EVC settings, so removed it from the script.  See - http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1012864



  • 20.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 27, 2015 08:30 PM

    Mark would it be okay if I try to add resource pools?



  • 21.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 29, 2015 12:58 PM

    Feel free!  On my list, but lower priority as we don't use them :smileysad:.



  • 22.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 27, 2015 09:05 PM

    Mark, thank you for the quick reply with the script.



  • 23.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 28, 2015 03:52 PM

    Now im getting errors when I get to the import folders function

    Please confirm your information before proceeding

    Target cluster         - ****

    Source vCenter         - ****

    Source Datacenter      - *****

    Destination vCenter    - *****

    Destination datacenter - *****

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

    Running QA tests against the information provided

    Cluster **** DOES exist in *****

    Checking connection to the ESX hosts with the root password provided

    *Script will halt if incorrect password is detected

    Datacenter ***** DOES exist in *****

    1

    Exporting folders in source datacenter *****

    Importing folders to destination datacenter *****

    Confirm

    Confirm

    1/28/2015 10:47:00 AM Get-Folder  Folder with name '*******' was not found using the specified filter(s).

    [Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): a

    get-folder : 1/28/2015 10:47:00 AM    Get-Folder        Folder with name 'Charlotte' was not found using the specified filter(s).

    At C:\users\rnotaro\downloads\Migration Script\Migration Script\Functions\import_folder_function.ps1:28 char:61

    +         $location = Get-Datacenter $dc | get-folder $type | get-folder $key

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

        + CategoryInfo          : ObjectNotFound: (:) [Get-Folder], VimException

        + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetFolder

    Action to take for this exception:

    1/28/2015 10:47:04 AM New-Folder  Value cannot be found for the mandatory parameter Location

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

    New-Folder : 1/28/2015 10:47:04 AM    New-Folder        Value cannot be found for the mandatory parameter Location

    At C:\users\rnotaro\downloads\Migration Script\Migration Script\Functions\import_folder_function.ps1:33 char:11

    +           New-Folder -Name $folder.Name -Location $location

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

        + CategoryInfo          : NotSpecified: (:) [New-Folder], VimException

        + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewFolder



  • 24.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 28, 2015 04:06 PM

    Can you attach this file from the script run if it's safe to do so (company info)?

    .\$SourcevCenter\$Cluster\folderexport.csv



  • 25.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 28, 2015 04:19 PM

    No but it looks like this.  it has 67 rows and 3 columns

    NamePathType
    cluster1DC\cluster1blue
    cluster2DC\cluster2blue


  • 26.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 28, 2015 04:38 PM

    Ok, trying to understand what makes your folder structure different.  Mine in testing was setup like this:

    Name is the actual name of the folder.

    Path is the path of the folder.  vm\ is the datacenter, next is Discovered virtual machine folder and sub folders underneath the Discovered virtual machine level folder.

    Type is all blue or virtual machine folder.

    NamePathType
    Discovered virtual machinevm\Discovered virtual machineblue
    Level1Cvm\Discovered virtual machine\Level1Cblue
    Level1Bvm\Discovered virtual machine\Level1Bblue
    Level1Avm\Discovered virtual machine\Level1Ablue
    Level2Cvm\Discovered virtual machine\Level1C\Level2Cblue
    Level2Bvm\Discovered virtual machine\Level1B\Level2Bblue
    Level2Avm\Discovered virtual machine\Level1A\Level2A

    blue

    From what you provided it looks like the name field has names of clusters?  Where is the folder that threw an error located in the folder chain?  IE, is it a top-level folder where creation was attempted first?



  • 27.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 28, 2015 05:04 PM

    Cluster1 is just name of the folder that the vms are stored.   It happens to be the same name as the cluster.  Each cluster is its own client.  

    All the folders are under the Datacenter object so DC\Cluster1, DC\Cluster2, etc

    The error is on the datacenter name. Thats what it is saying it cant find.   Do I need to make a folder below the Datacenter object and put all my vm folders in that for the script to work?



  • 28.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 28, 2015 07:34 PM

    You can try that, but first edit the import_folder_function.ps1 script and remove this error action handling part:

    BEFORE

      foreach($folder in $VMfolder){

          $key = @()

          $key =  ($folder.Path -split "\\")[-2]

          if ($key -eq "vm") {

             get-datacenter $dc | get-folder $type | New-Folder -Name $folder.Name -ErrorAction SilentlyContinue

          } else

         {

    AFTER

      foreach($folder in $VMfolder){

          $key = @()

          $key =  ($folder.Path -split "\\")[-2]

          if ($key -eq "vm") {

             get-datacenter $dc | get-folder $type | New-Folder -Name $folder.Name

          } else

         {

    I'm thinking it is throwing an error before, but not exposing it.



  • 29.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 28, 2015 08:50 PM

    I noticed that import script sets the $type variable to "vm" but all of mine in my CSV are type "blue"   Not sure if thats part of the problem.



  • 30.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 28, 2015 08:39 PM

    Looks the same with that piece removed.   

    Confirm

    1/28/2015 03:20:42 PM Get-Folder  Folder with name 'AS' was not found using the specified filter(s).

    [Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"):

    get-folder : 1/28/2015 03:20:42 PM    Get-Folder        Folder with name 'AS' was not found using the specified filter(s).

    At C:\users\rnotaro\downloads\Migration Script\Migration Script\Functions\import_folder_function.ps1:28 char:61

    +         $location = Get-Datacenter $dc | get-folder $type | get-folder $key

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

        + CategoryInfo          : ObjectNotFound: (:) [Get-Folder], VimException

        + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetFolder

    Action to take for this exception:

    1/28/2015 03:20:42 PM New-Folder  Value cannot be found for the mandatory parameter Location

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

    New-Folder : 1/28/2015 03:20:42 PM    New-Folder        Value cannot be found for the mandatory parameter Location

    At C:\users\rnotaro\downloads\Migration Script\Migration Script\Functions\import_folder_function.ps1:33 char:11

    +           New-Folder -Name $folder.Name -Location $location

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

        + CategoryInfo          : NotSpecified: (:) [New-Folder], VimException

        + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewFolder



  • 31.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 28, 2015 08:48 PM

    Ok, I think I know what's going on.  The function sorts the csv it uses by the Path column.

    Path
    vm\Discovered virtual machine
    vm\Discovered virtual machine\Level1C
    vm\Discovered virtual machine\Level1B
    vm\Discovered virtual machine\Level1A
    vm\Discovered virtual machine\Level1C\Level2C
    vm\Discovered virtual machine\Level1B\Level2B
    vm\Discovered virtual machine\Level1A\Level2A

    So, in my case the sort is actually aligning the folders in the order they will be created.  I think what is going on in your case is that when it does the sort it arranges the rows in a way that is causing the error - IE, the rows are not building on each other when it goes to import the folders back in.  Does this make sense and if so, take a look at your export csv and see if the logic holds true.  Basically, the first row (folder) must be implemented before the second one can be and so on.

    For example, this would fail in my environment as the first level folder would not be created first.  I can't imagine right now exactly what folder layout would cause problems, but I'm thinking that is what's going on.

    Path
    vm\Discovered virtual machine\Level1A\Level2A
    vm\Discovered virtual machine
    vm\Discovered virtual machine\Level1C
    vm\Discovered virtual machine\Level1B
    vm\Discovered virtual machine\Level1A
    vm\Discovered virtual machine\Level1C\Level2C
    vm\Discovered virtual machine\Level1B\Level2B


  • 32.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 28, 2015 09:06 PM

    I noticed you dont have a datacenter in your path so the script must not be pulling that in for you but for me it is

    So lets say my first folder name is Red and my datacenter name is Colors

    The the first line in my export csv is

    Name               Path                    type

    Red                  Colors\Red          blue

    When it goes to import it back into the new VC there is no Colors datacenter obviously so is that why its failing?



  • 33.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 29, 2015 12:56 PM

    Interesting, so the first record in your csv in the path column is Colors?  Like this? - ignore the other items in the path, just keying on the first one.

    Path

    Colors\Discovered virtual machine\Level1A\Level2A

    Colors\Discovered virtual machine

    Colors\Discovered virtual machine\Level1C

    Colors\Discovered virtual machine\Level1B

    Colors\Discovered virtual machine\Level1A

    Colors\Discovered virtual machine\Level1C\Level2C

    Colors\Discovered virtual machine\Level1B\Level2B

    If this is the case you may want to try to edit this portion of the import_folder_function.ps1

    BEFORE

    #Loop to import folders.  Objects are sorted by path field in above import.

    #Splits records by slashes and sets key as record just prior to last record. 

    #The if loop then creates the first folder and then the next does all the rest

    # of the folders.  The entire loop will fail without the first creation of the "vm" folder.

    #Error action on first folder creation is set as this first folder, Discovered virtual machine folder will trigger errors after the first script run on a datacenter.

      foreach($folder in $VMfolder){

          $key = @()

          $key =  ($folder.Path -split "\\")[-2]

          if ($key -eq "vm") {

             get-datacenter $dc | get-folder $type | New-Folder -Name $folder.Name -ErrorAction SilentlyContinue

          } else

         {

            $location = Get-Datacenter $dc | get-folder $type | get-folder $key

            Try{

              Get-Folder -Name $folder.Name -Location $location -ErrorAction Stop

            }

            Catch{

              New-Folder -Name $folder.Name -Location $location

            }

          }

       }

    }

    AFTER (Only adjusting the initial key scan to Colors instead of "vm".)

    #Loop to import folders.  Objects are sorted by path field in above import.

    #Splits records by slashes and sets key as record just prior to last record. 

    #The if loop then creates the first folder and then the next does all the rest

    # of the folders.  The entire loop will fail without the first creation of the "vm" folder.

    #Error action on first folder creation is set as this first folder, Discovered virtual machine folder will trigger errors after the first script run on a datacenter.

      foreach($folder in $VMfolder){

          $key = @()

          $key =  ($folder.Path -split "\\")[-2]

          if ($key -eq "Colors") {

             get-datacenter $dc | get-folder $type | New-Folder -Name $folder.Name -ErrorAction SilentlyContinue

          } else

         {

            $location = Get-Datacenter $dc | get-folder $type | get-folder $key

            Try{

              Get-Folder -Name $folder.Name -Location $location -ErrorAction Stop

            }

            Catch{

              New-Folder -Name $folder.Name -Location $location

            }

          }

       }

    }



  • 34.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 29, 2015 02:42 PM

    Ok that fixed that issue! 

    Now when it gets down to the part where it adds the hosts to the new vCenter it fails again.

    Finished removing.  Disconnecting from the source vCenter  BLAH

    Adding the hosts into tne new cluster CLUSTER on BLAH2

    Confirm

    1/29/2015 09:19:46 AM Add-VMHost  The specified parameter 'Location' expects a single value, but your name criteria 'CLUSTER' corresponds to multiple values.

    [Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): y

    Add-VMHost : 1/29/2015 09:19:46 AM    Add-VMHost        The specified parameter 'Location' expects a single value, but your name criteria 'CLUSTER' corresponds

    to multiple values.

    At C:\users\rnotaro\downloads\Migration Script\Migration Script\FROMCSV_vCenterMigration.ps1:532 char:33

    + foreach ($vmhost in $CSVhosts) {Add-VMHost $vmhost.name -Location $Cluster -User ...

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

        + CategoryInfo          : InvalidResult: (System.Collecti...dObjectInterop]:List`1) [Add-VMHost], VimException

        + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResultsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.AddVMHost

    Confirm

    1/29/2015 09:20:08 AM Add-VMHost  VIContainer parameter: Could not find any of the objects specified by name.

    [Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): y

    Add-VMHost : 1/29/2015 09:20:08 AM    Add-VMHost        VIContainer parameter: Could not find any of the objects specified by name.

    At C:\users\rnotaro\downloads\Migration Script\Migration Script\FROMCSV_vCenterMigration.ps1:532 char:33

    + foreach ($vmhost in $CSVhosts) {Add-VMHost $vmhost.name -Location $Cluster -User ...

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

        + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...tainer Location:RuntimePropertyInfo) [Add-VMHost], ObnRecordProcessingFailedException

        + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore.Cmdlets.Commands.AddVMHost

    Confirm

    1/29/2015 09:20:28 AM Add-VMHost  The specified parameter 'Location' expects a single value, but your name criteria 'CLUSTER' corresponds to multiple values.

    [Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): a

    Add-VMHost : 1/29/2015 09:20:28 AM    Add-VMHost        The specified parameter 'Location' expects a single value, but your name criteria 'CLUSTER' corresponds

    to multiple values.

    At C:\users\rnotaro\downloads\Migration Script\Migration Script\FROMCSV_vCenterMigration.ps1:532 char:33

    + foreach ($vmhost in $CSVhosts) {Add-VMHost $vmhost.name -Location $Cluster -User ...

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

        + CategoryInfo          : InvalidResult: (System.Collecti...dObjectInterop]:List`1) [Add-VMHost], VimException

        + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResultsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.AddVMHost

    Add-VMHost : 1/29/2015 09:20:46 AM    Add-VMHost        VIContainer parameter: Could not find any of the objects specified by name.

    At C:\users\rnotaro\downloads\Migration Script\Migration Script\FROMCSV_vCenterMigration.ps1:532 char:33

    + foreach ($vmhost in $CSVhosts) {Add-VMHost $vmhost.name -Location $Cluster -User ...

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

        + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...tainer Location:RuntimePropertyInfo) [Add-VMHost], ObnRecordProcessingFailedException

        + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore.Cmdlets.Commands.AddVMHost



  • 35.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 29, 2015 03:49 PM

    Can you please try this?

    Close all powercli sessions.  Launch a new powercli session and do not connect to any vCenter servers.  Run this to confirm - disconnect-viserver * -confirm:$false

    Now try and run the script.  I think that error is being caused by another vCenter session being open.

    *When I kill the script mid-run I always perform a quick clean up by running these two commands:

    stop-transcript

    and

    disconnect-viserver * -confirm:$false



  • 36.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 29, 2015 05:20 PM

    Ok I did that and ran the command to disconnect vcenter.  Same error.

    I manually added the hosts so the script would continue and it gives a similar error later in the script. 

    Importing permissions for the folders, hosts, virtual machines, datacenter and cluster

    Importing DRS rules (if any were exported)

    Importing VM folder locations

    Confirm

    1/29/2015 11:06:33 AM Move-VM  The specified parameter 'Destination' expects a single value, but your name criteria 'CLUSTER' corresponds to multiple values.

    [Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): y

    Move-VM : 1/29/2015 11:06:33 AM    Move-VM        The specified parameter 'Destination' expects a single value, but your name criteria 'CLUSTER' corresponds

    to multiple values.

    At C:\users\rnotaro\Downloads\Migration Script\Migration Script\FROMCSV_vCenterMigration.ps1:662 char:105

    + ... ne") { } else {Move-VM -VM $vm.Name -Destination $vm.Folder -RunAsync}}

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

        + CategoryInfo          : InvalidResult: (System.Collecti...dObjectInterop]:List`1) [Move-VM], VimException

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



  • 37.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 29, 2015 09:38 PM

    ok, I believe the issue is that the cluster name and folder name are the same and thats where the multiple names are coming from.  I renamed my folder to be different from the cluster name and the script finished!   Maybe there's a way to identtfy the folder or cluster by id instead of name?



  • 38.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 30, 2015 07:48 PM

    So, one thing I am finding is that the import portion of the script does not like:

    1.     Duplicate folder names that exist under the same vCenter - ie, the same folder name existing say in different datacenters under the same VC.

    2.     VMs that are placed in the "vm" folder as this is a hidden type folder and it chokes when it tries to import them in.

    Working now to update the script for this - may be related to what you are seeing.  We've used the script hundreds of times on more simple clusters as far as layouts go and we are moving to more complex environments (larger folder trees, complex provisioning/placement), so that's why I haven't see this error before.



  • 39.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 30, 2015 08:59 PM

    I'll update the script, but I added this tidbit to narrow down the scope to the datacenter you are working with.

    #Import folder permissions.  Will be executed at operator's discretion.

    #Note that the $folder value is narrowed down to the destinationdatacenter as a duplicate folder in another datacenter will cause an error.

    $folderperms = Import-Csv "./$SourcevCenter/$Cluster./perms_export_folders.csv"

    foreach ($fpm in $folderperms) {

      $svcgroup = $fpm.Principal

      $folder = Get-Datacenter $DestinationDatacenter | Get-Folder -Name $fpm.Entity

      $authMgr = Get-View AuthorizationManager

      $perm = New-Object VMware.Vim.Permission

      $perm.principal = $svcgroup

      $perm.group = if ($fpm.IsGroup -eq "TRUE") {$true} else {$null}

      $perm.propagate = if ($fpm.Propagate -eq "TRUE") {$true} else {$null}

      $perm.roleid = ($authMgr.RoleList | where{$_.Name -eq $fpm.Role}).RoleId

      $authMgr.SetEntityPermissions(($folder | Get-View).MoRef, $perm)

    Trying to figure out how to narrow this down now:

    #Begin import of virtual machine folder locations

    $VMFolderLocationImport = Import-Csv .\folderlocation_export_vms.csv

    Write-Host " "

    Write-Host "Importing" -ForegroundColor Green -NoNewline

    Write-Host " VM folder locations"

    foreach ($vm in $VMFolderLocationImport) { If ($vm.Folder -Like "Discovered virtual machine") { } else {Move-VM -VM $vm.Name -Destination $vm.Folder -RunAsync}}

    #End import of virtual machine folder locations



  • 40.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jan 30, 2015 09:29 PM

    Here is the updated version, but still working on this portion:

    #Begin import of virtual machine folder locations

    $VMFolderLocationImport = Import-Csv .\folderlocation_export_vms.csv

    Write-Host " "

    Write-Host "Importing" -ForegroundColor Green -NoNewline

    Write-Host " VM folder locations"

    foreach ($vm in $VMFolderLocationImport) { If ($vm.Folder -Like "Discovered virtual machine") { } else {Move-VM -VM $vm.Name -Destination $vm.Folder -RunAsync}}

    #End import of virtual machine folder locations

    So, if the folder the script is trying to move the VM back to is not unique within the vCenter (ie, the folder name exists under two or more datacenters within your destination vCenter) it will error out.



  • 41.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Feb 05, 2015 02:14 PM

    FYI - Known issues that may cause problems:

    1.     Folders that are the same name as the cluster or datacenter or contain the cluster or datacenter name in them.

    2.     Duplicate folder names under the same datacenter.  Does not matter if folders are in different locations within the folder tree (ie, one is two levels down or one is top level etc).



  • 42.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Feb 06, 2015 01:03 PM

    Hi Mark,

    thank you very much for your effort and hard work on the script. Could you please advise what could cause the following errors when running the latest version of the migration script?

    "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."

    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.

    Transcript is attached...

    Thank you very much for your help in advance.

    Michal



  • 43.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Feb 06, 2015 02:57 PM

    Is this taking place during the folder import section and can you provide an example of how your folder tree is laid out?



  • 44.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Feb 06, 2015 03:04 PM

    Yes, it's during the folder export section. The folder tree of the Datacenter I'd like to migrate is attached...



  • 45.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Feb 06, 2015 03:35 PM

    Can you try this? - trying to narrow things down.

    1.     Unzip the attached to a folder.

    2.     Login to your vcenter via powercli.

    3.     Run get_folder_path.ps1

    Let me know if you hit the same errors.



  • 46.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Feb 06, 2015 03:44 PM

    Thank you. This time there are no errors and the output.csv is filled with the folder structure...



  • 47.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Feb 06, 2015 04:21 PM

    I'm getting the same error with the latest version.  Looks like I am a victim of my own poor, version control :smileyhappy:.  I have "sanitize" the script each time and I must have missed something.  Let me adjust the one I'm using in prod and get it up on this post.  I"ll try to get it up today.  Thanks. - wouldn't waste any more time on the other.



  • 48.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Feb 06, 2015 05:28 PM

    Please try this version Romino and let me know how it goes.  The only errors I've seen with my layout is when I have duplicate folders under the datacenter or when I have folders with non-standard naming convention (brackets etc.)



  • 49.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Feb 09, 2015 09:34 AM

    Hi Mark, thank you very much for your quick response and script fix. I successfully passed the folder creation phase this time. The script failed at creating the new cluster in the new vCenter with the following error:

    Action to take for this exception:

    Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

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

    New-Cluster : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

    At C:\tmp\vCenterMirationScript_2_6_2015\FROMCSV_vCenterMigration.ps1:324 char:49

    +    New-Cluster -Location $DestinationDatacenter @splat

    +                                                 ~~~~~~

        + CategoryInfo          : InvalidData: (:) [New-Cluster], ParameterBindingValidationException

        + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewCluster

    .....Configuring HA settings for cluster Hroch in vCenter vc-cz-4.cz.moravia-it.com under datacenter dc4Hilleho

    Action to take for this exception:

    Cannot validate argument on parameter 'HARestartPriority'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

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

    Set-Cluster : Cannot validate argument on parameter 'HARestartPriority'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

    At C:\tmp\vCenterMirationScript_2_6_2015\FROMCSV_vCenterMigration.ps1:361 char:34

    +    Set-Cluster -Cluster $Cluster @splat

    +                                  ~~~~~~

        + CategoryInfo          : InvalidData: (:) [Set-Cluster], ParameterBindingValidationException

        + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetCluster

    .....Configuring DRS settings for cluster Hroch in vCenter vc-cz-4.cz.moravia-it.com under datacenter dc4Hilleho

    Action to take for this exception:

    Cannot validate argument on parameter 'DrsAutomationLevel'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

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

    Set-Cluster : Cannot validate argument on parameter 'DrsAutomationLevel'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

    At C:\tmp\vCenterMirationScript_2_6_2015\FROMCSV_vCenterMigration.ps1:393 char:34

    +    Set-Cluster -Cluster $Cluster @splat

    +                                  ~~~~~~

        + CategoryInfo          : InvalidData: (:) [Set-Cluster], ParameterBindingValidationException

        + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetCluster

    Thank you very much for your further advice in advance!



  • 50.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Feb 18, 2015 08:52 PM

    Can you share the contents of this file (and sanitize if need be)?

    .\$SourcevCenter\$Cluster\$Cluster.csv

    Should look something like this:

    "Name","HAEnabled","HAAdmissionControlEnabled","HAFailoverLevel","HARestartPriority","HAIsolationResponse","DrsEnabled","DrsAutomationLevel","EVCMode"

    "ClusterName","False","False","1","Medium","DoNothing","True","FullyAutomated","intel-westmere"



  • 51.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 02, 2015 10:18 AM

    HI Mark, sorry for the delay, I was out of the office. Please find the csv file attached - could be the problem that there are semicolons instead of commas? I tried again today and keep getting the same errors ('New-Cluster : Cannot validate argument on parameter 'Name'. The argument is null or empty.' and so on). Thank you very much for your advice.



  • 52.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 02, 2015 01:00 PM

    Hmm, those (semicolons) certain can't be helping the situation, but the error you're receiving should be calling information from the VMHost.csv file.  Can you provide the contents of that file?  Should be similar to this:

    "Name"

    "servername1esx.company.com"

    "servername2esx.company.com"



  • 53.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 02, 2015 01:03 PM

    Sure, attached. Thank you.



  • 54.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 02, 2015 01:50 PM

    You're dead on, I think it is the semicolon usage.  Can you connect into your source vCenter server with powercli and run this command?

    Get-Cluster -name Hroch | Select Name, HAEnabled, HAAdmissionControlEnabled, HAFailoverLevel, HARestartPriority, HAIsolationResponse, DrsEnabled, DrsAutomationLevel, EVCMode | Export-Csv -NoTypeInformation -UseCulture -Path .\Hroch.csv

    Then, you could also add this in < - Delimiter "," >, but just for testing as you want to correct this at a higher level than going into the script and always adding the delimiter..

    Get-Cluster -name Hroch | Select Name, HAEnabled, HAAdmissionControlEnabled, HAFailoverLevel, HARestartPriority, HAIsolationResponse, DrsEnabled, DrsAutomationLevel, EVCMode | Export-Csv -Delimiter "," -NoTypeInformation -UseCulture -Path .\Hroch.csv


    I think we'll be good once we determine why the export-csv is exporting using semicolons instead of commas.


    My export looks like this..

    "Name","HAEnabled","HAAdmissionControlEnabled","HAFailoverLevel","HARestartPriority","HAIsolationResponse","DrsEnabled","DrsAutomationLevel","EVCMode"

    "C001","True","True","1","Medium","DoNothing","True","FullyAutomated",

    Also, let's check your powercli version (below is my version):

    PowerCLI C:\Scripts\misc\3_2> Get-VIToolkitVersion

    PowerCLI Version

    ----------------

       VMware vSphere PowerCLI 5.5 Release 2 build 1671586

    ---------------

    Snapin Versions

    ---------------

       VMWare AutoDeploy PowerCLI Component 5.5 build 1598391

       VMWare ImageBuilder PowerCLI Component 5.5 build 1598391

       VMware License PowerCLI Component 5.5 build 1265954

       VMware VDS PowerCLI Component 5.5 build 1671576

       VMware vSphere PowerCLI Component 5.5 build 1671576

    And powershell:

    PowerCLI C:\Scripts\misc\3_2> $PSVersionTable.PSVersion

    Major  Minor  Build  Revision

    -----  -----  -----  --------

    3      0      -1     -1

    *Of note.  Look at these to try and correct the overall export-csv, semicolon problem.

    Exporting to CSV-format using comma instead of Semicolon

    CSV with comma or semicolon? - Stack Overflow



  • 55.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 02, 2015 02:02 PM

    I might have found out the reason for the semicolon usage - it's the Czech regional settings in Windows. After I changed the "List separator" from ";" to ",", I got _comma separated values_ :-) I will try to restart the migration and let you know the outcome. Thank you very much for your help!



  • 56.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 02, 2015 02:06 PM

    Anytime.  Are you Czech?  If so, I'll do all I can to help you as I'm 50% Czech!!  :smileywink:



  • 57.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 02, 2015 02:29 PM

    Yes, I am Czech :-) The script finished almost successfully. Everything is in its right place except for the distributed switch. The networking is fine on the hosts but on the vCenter side I cannot add the hosts into the vDS with the following error:

    vDS operation failed on host esx-cz-10.cz.moravia-it.com, Received SOAP response fault from [<cs p:00007f85585249c0, TCP:esx-cz-10.cz.moravia-it.com:443>]: invokeHostTransactionCall

    Received SOAP response fault from [<cs p:1f3f3230, TCP:localhost:8307>]: invokeHostTransactionCall

    An error occurred during host configuration. got (vim.fault.PlatformConfigFault) exception

    vDS operation failed on host esx-cz-11.cz.moravia-it.com, Received SOAP response fault from [<cs p:00007f857c76d710, TCP:esx-cz-11.cz.moravia-it.com:443>]: invokeHostTransactionCall

    Received SOAP response fault from [<cs p:1f3f9030, TCP:localhost:8307>]: invokeHostTransactionCall

    An error occurred during host configuration. got (vim.fault.PlatformConfigFault) exception

    Could you please advise?



  • 58.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 02, 2015 03:11 PM

    I've only been to the Czech Republic once, but I really enjoyed it.

    I am very green on vDS, but this looks like it may help - VMware KB: Unable to add a virtual machine to a vSphere Distributed Switch 5.5 portgroup with traffic filtering rule…



  • 59.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 03, 2015 08:20 AM

    I didn't manage to make it work with the virtual Distributed Switch so I reconnected back to the old vCenter. Fortunately, no harm to the production environment has been done. Would it be possible to implement the vDS migration into this awesome script in future? Thank you very much for your hard work!



  • 60.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 03, 2015 01:34 PM

    Hate to hear that Romino :smileysad:.  We currently do not have vDS implemented, but most likely will move to it in v6.  I'll take a look to see if that would be easy to do or not.



  • 61.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 03, 2015 06:38 PM

    Quick question on the DVS side.  Before you remove the host from the 1st vCenter, are you disconnecting any physical NICs from the DVS before migrating?  I remember working on a script very similar to this (outside of many of the settings that I did not need to replicate exactly in the 2nd vCenter).

    What I did was removed one of the physical NICs from the DVS in the 1st vCenter:

    Get-VMHost -Name $vmhost.Name | Get-VMHostNetworkAdapter -Physical -Name vmnic0 | Remove-VDSwitchPhysicalNetworkAdapter -Confirm:$false

    That way, I had one physical NIC that I could attach to the DVS in the new vCenter that was not associated with the old vCenter's DVS.  vmnic1 was still active for the VM connections and would continue to be when I disconnected the host from the 1st vCenter and added it to the second vCenter (don't know whether that's technically supported, per se, but it worked....it was like creating a scenario where vCenter was down...you rely on the local DVS information on the host to operate).

    When I added the host into the second vCenter, I'd then add the host to the new DVS and then add vmnic0 to the new DVS:

    $dvs = Get-VDSwitch $newDVS

    foreach ($vmhost in $vmhosts)

    {

         Add-VDSwitchVMHost -VDSwitch $dvs -VMHost $vmhost.Name -Confirm:$false

         $vmhostNA = Get-VMHost -Name $vmhost.Name | Get-VMHostNetworkAdapter -Physical -Name vmnic0

         $dvs | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNA -Confirm:$false

    }

    After that, I was then able to start migrating VMs over to the new DVS portgroups (which I had created earlier), along with vmkernel ports.

    If you haven't, I'd recommend disconnecting a physical NIC from the DVS (assuming redundant NICs) in the 1st vCenter, otherwise, you may have lingering DVS configuration issues that may be causing your message in question.

    For the record, I did have to resort to this due to private VLANs.  Converting everything back to a standard vSwitch was going to knock too many live VMs offline to migrate.  Had to keep them up with minimal impact (maybe 1-2 pings missed for the VM when transitioning over from cached DVS info to 2nd vCenter's portgroup).



  • 62.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 03, 2015 07:01 PM

    We've continued to push vDS implementation year after year and have not yet implemented, so I actually don't deal with vDS within the script.  Most likely we'll be looking at it again for version 6, but that's a ways out for us.  My goal for version 6 is to completely automate VC builds and migrations, so we can just set schedules and be notified if something goes wrong during the script run - I could pretty much do that now with the migration piece as the script just cycles through a csv file for clusters to migrate.  Thinking of moving to a more advanced way of doing this by actually looking at two environments and migrate things to a certain location based on rules (ie, this region's VC handles these clusters etc..) *Sorry, just noticed you were responding to Romino - :smileyhappy:



  • 63.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 03, 2015 07:50 PM

    No worries.  I'm just trying to remember if I had seen his error before.  When I was testing all that out (oh, it's been about a year since I wrote that original migration script my old employer used to mass migrate clusters from large vCenters to individual data center room vCenters....went from 2 total vCenters to something like 10 individual vCenters).  I remember trying to do the initial testing without removing physical NICs from the DVS and I had nothing but problems since the local cached information was still tied to those physical NICs.  Removing just a single NIC and then add the host/physical NIC to the new vCenter and DVS rectified the issue.

    I'm pretty sure it's not exactly a method that VMware support would approve of, but it works!

    --j



  • 64.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 04, 2015 07:41 AM

    Thank you for the tip. I will try to proceed with removing the NIC first. Private VLANs are in place here as well. Would you be so kind and post your migration script here? Thank you!



  • 65.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 04, 2015 01:09 PM

    Let me see what I can do with that script to sanitize it and post it.  I've been meaning to do so for quite sometime, but it keeps getting pushed back due to other efforts.  :smileyhappy:



  • 66.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Feb 18, 2015 08:00 PM

    Mark,

    I was referred to your script and I am a complete novice when it comes to this.  I am trying to figure out how I can accomplish the following.

    Moving one cluster of hosts and VMs from one vCenter to the new one (5.0 to 5.5) and arranging the VMs back into their respective folders on the new side.  I don't mind having to manually create all the folders in the new vCenter.  I just don't want to have to drag and drop all of the VMs and sort.  I'm not worried about permissions, HA/DRS settings, etc.  I just want to be able to script the moving of VMs into their folders.

    Any help would be appreciated.



  • 67.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Feb 18, 2015 08:58 PM

    It's pretty easy Jesse, just unzip the contents of the latest script zip file.  Populate the contents of the EXAMPLE.CSV file with your information:

    Your CSV can have one record:

    SourceVC,destinationVC,Sourcecluster,SourceDC,DestinationDC

    sourceVCname,destinationVCname,clustername,sourceDatacentername,destinationdatacentername

    Or two records:

    SourceVC,destinationVC,Sourcecluster,SourceDC,DestinationDC

    sourceVCname,destinationVCname,clustername,sourceDatacentername,destinationdatacentername

    sourceVCname,destinationVCname,clustername,sourceDatacentername,destinationdatacentername

    Or more:

    SourceVC,destinationVC,Sourcecluster,SourceDC,DestinationDC

    sourceVCname,destinationVCname,clustername,sourceDatacentername,destinationdatacentername

    sourceVCname,destinationVCname,clustername,sourceDatacentername,destinationdatacentername

    sourceVCname,destinationVCname,clustername,sourceDatacentername,destinationdatacentername

    sourceVCname,destinationVCname,clustername,sourceDatacentername,destinationdatacentername

    sourceVCname,destinationVCname,clustername,sourceDatacentername,destinationdatacentername

    sourceVCname,destinationVCname,clustername,sourceDatacentername,destinationdatacentername

    Save the adjusted EXAMPLE.CSV file.

    Launch PowerCLI as admin and navigate to where you unzipped the migration script to.  Launch FROMCSV_vCenterMigration.ps1 and follow the prompts.  The first user credentials will be the one doing all the work in vCenter (disconnecting hosts, etc), so it will most likely need to be your admin account in vSphere.  The script will ignore permissions etc if they don't exist, but it will create the folders in the new datacenter and place the VMs in the correct folders.

    Please pay attention to these gotchas and notes on the script

    Known Issues:

    1.     Duplicate folder names that exist under the same vCenter - ie, the same folder name existing say in different datacenters under the same VC.

    Misc:

    - 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



  • 68.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jul 02, 2015 01:27 PM

    What data and format is supposed to be in the .csv file on line 38?  The script asks for the file to import and dies if pointed to an empty file.

    Thank you



  • 69.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jul 02, 2015 01:39 PM

    Disregard.  I found the example csv



  • 70.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jul 02, 2015 02:03 PM

    Very cool.  Also, pay attention to the readme in the main folder as it lists out some gotchas I hit.



  • 71.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Aug 13, 2015 10:58 AM

    Hi all!

    !i don't know if im in the right place here,

    i'm quite new to these environments but i have a question regarding nutanix 1050 & 3050 hosts with vmware

    using vCenter Appliance 5.5 on both nutanix servers

    1 vcenter 5.5 on nutanix 1050

    1 vcenter 5.5 on nutanix 3050

    both in its own SSO

    current situation:

    at this moment i have in one vcenter with 2 clusters with each 4 hosts and on each hosts there is a CVM running on it. connected to a Distributed Switch,

    so what i see is nutanix 1050 - 4 hosts + nutanix 3050 + 4 hosts

    future situation

    now what i want to do is grab 1 cluster and move it to the other vcenter. can you please advice me what i need to do or steps i need to take,

    i will be very greatful ,

    regards

    Robbert

    under supervision of Fred



  • 72.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 01, 2016 08:49 PM

    I have not use it yet but I'm going to have a look at it to see if I can use it in my migrations.

    The scripts seems very interesting.

    Just as an added benefit you might want to put a header on you script to make it easier to understand and use.

    I've attached what I use as a header for my scripts and ii makes get help from PowerShell very easy if the format is followed.

    Just my 2 cents



  • 73.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 17, 2015 02:33 PM

    Hi Mark

    I'm testing out the script in my lab before deploying it to migrate two clusters of three hosts each from vCenter 5.1u1 to vCSA 5.5

    I've hit a snag just after it removes the hosts from the first cluster. The following error happens 13 times and none of the permissions are applied to the folders

    Importing permissions for the folders, hosts, virtual machines, datacenter and cluster

    Action to take for this exception:

    Exception calling "SetEntityPermissions" with "2" argument(s): "The object or item referred to could not be found."

    [C] Continue  [I] Silently Continue  [B] Break  [S] Suspend  [?] Help

    (default is "C"):

    Exception calling "SetEntityPermissions" with "2" argument(s): "The object or item referred to could not be found."

    At C:\Move\vCenterMirationScript_2_6_2015\FROMCSV_vCenterMigration.ps1:579 char:3

    +         $authMgr.SetEntityPermissions(($folder | Get-View).MoRef, $perm)

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

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : VimException

    I've attached the perms_export_folders.csv

    Folders are created correctly, and the VMs do move into the correct folders, but from the "Tasks and Events" screen it looks like the folders are being created twice



  • 74.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 17, 2015 03:05 PM

    Hey andjest.

    Three things the script does not handle well (or at all :smileyhappy:)

    1. Duplicate folder names (within the scope of a vCenter server).

    2. Folder names that connect brackets < [ ] >

    3. Folder names that are the same name as the datacenter they reside under.

    You should have smooth sailing if you remove these three points of failure.  I haven't put much time into getting around these as I am trying to move in the direction of tags.  Folder imports and VM placements in those folders takes forever.  For example, we are seeing a cluster without folders take ~6 minutes to migrate and those with VMs in folders (100+ VMs) are taking 45+ minutes.  Just doesn't connect up with the vision I have for speeding everything thing up going forward.  Just rename the source folders you have to make them unique (ie, I just add the parent folder name - parentfoldername_childfoldername) to make them unique.



  • 75.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 17, 2015 05:56 PM

    I can confirm there are no duplicate folder names, no folder names that match the datacenter name, no folder names for my datastores that match anything

    I do have resource pools that match folder names... Could that be causing it?



  • 76.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 17, 2015 07:16 PM

    Can you confirm when the error hits?  From your post you say it takes place after the hosts are removed from the first cluster, but from the error, to me this should take place after the hosts are confirmed to have been connected.  This is where I am envisioning the error taking place?:

    #Checking that the the hosts are connected before proceeding

    foreach ($vmhost in $CSVhosts) {

      Do {

          $status = Get-VMHost -Name $vmhost.name | Select -ExpandProperty ConnectionState

          Write-Output "Connection state of $($vmhost.name) = $status - Process will proceed when host status is connected or maintenance mode"

          Start-Sleep -Seconds 1

      }

      While ($waitForThese -notcontains $status)

    }

    #Import of permissions

    Write-Host "Importing" -ForegroundColor Green -NoNewline

    Write-Host " permissions for the folders, hosts, virtual machines, datacenter and cluster

    "

    Start-Sleep -Seconds 1

    #Import folder permissions.  Will be executed at operator's discretion.

    #Note that the $folder value is narrowed down to the destinationcenter as a duplicate folder in another datacenter will cause an error.

    $folderperms = Import-Csv "./$SourcevCenter/$Cluster./perms_export_folders.csv"

    foreach ($fpm in $folderperms) {

      $svcgroup = $fpm.Principal

      $folder = Get-Datacenter $DestinationDatacenter | Get-Folder -Name $fpm.Entity

      $authMgr = Get-View AuthorizationManager

      $perm = New-Object VMware.Vim.Permission

      $perm.principal = $svcgroup

      $perm.group = if ($fpm.IsGroup -eq "TRUE") {$true} else {$null}

      $perm.propagate = if ($fpm.Propagate -eq "TRUE") {$true} else {$null}

      $perm.roleid = ($authMgr.RoleList | where{$_.Name -eq $fpm.Role}).RoleId

      $authMgr.SetEntityPermissions(($folder | Get-View).MoRef, $perm)



  • 77.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 17, 2015 07:25 PM

    Hopefully it's this easy.  Can you make sure the roles exist in the new VC? - from the names, they look like custom adds.



  • 78.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 18, 2015 09:10 PM

    dVS is on our radar as well but with mismatched hosts and vswitch layouts I really don't want to run the risk of dumping production machines and being "that guy" who breaks critical business apps during working hours. Our change management process also prohibits a lot of production work during business hours which I'm sure most of you have as well.

    I would like to test this script out as I am migrating from the vAPP vCenter 5.5 to Win-OS based vCenter 6. We just got so fed up with the vAPP version of vCenter that we are going back to the Win-OS ver.

    Does this work for appliance -> windows based vcenters?



  • 79.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 19, 2015 12:29 PM

    I've only used it to go from 5.1 to 5.5 (all windows based VCs), but I see no reason why going from an appliance hosted VC would matter as they both respond the same to PowerCLI actions (I think).  Test it out in the lab definitely, but I've used it to successfully migrate 2k+ hosts and 20k+ vms so far.  Let me know how it goes, but look out for the 3 gotchas - using duplicate folder names, using brackets in folder names and using the datacenter name in folder names.



  • 80.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jun 05, 2015 05:18 AM

    Hi Mark,

    Amazing script... I only had a few problems with it... the largest one was probably the way it handled the Annotations at the end:

    Custom attributes and notes for MELMISVW02 (Glenn Win7 VDI) are being imported now...

    Confirm

    5/06/2015 3:09:16 PM Set-Annotation  Could not find annotation with name 'Availability'.

    [Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): a

    Set-Annotation : 5/06/2015 3:09:16 PM    Set-Annotation        Could not find annotation with name 'Availability'.

    At E:\scripts\vCenterMigrationUpdated\FROMCSV_vCenterMigration.ps1:684 char:4

    +    Set-Annotation -Entity (get-vm $vm.Name) -CustomAttribute $vm.DR -Value $vm." ...

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

        + CategoryInfo          : InvalidData: (:) [Set-Annotation], ViError

        + FullyQualifiedErrorId : Client20_InventoryServiceImpl_SetAnnotationValue_AnnotationNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetAn

       notation

    Confirm

    5/06/2015 3:09:33 PM Set-Annotation  Could not find annotation with name 'Backup Owner'.

    [Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): y

    Any time it couldn't find an annotation value it would prompt me for this... Now there may be holes like this on all our VM's... I can't really sit there accepting the prompt for 350+ VM's.

    The other two errors I faced were one during the folder creation and one during the permission configuration, but it doesn't appear to be anything major that I couldn't fix in a few seconds after the migration was complete... The annotations problem above is probably the biggest PITA.

    Attached is my transcript.



  • 81.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jun 05, 2015 05:24 AM

    If you add the switch -Confirm:$false to the Set-Annotation cmdlet, you will not the prompts (provided that is what you want).



  • 82.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jun 05, 2015 05:34 AM

    Actually looking through the annotations in my environment, there's annotations on probably only 3% of the VM's... What can I do to the script to skip the annotation copy entirely?

    I presume it's as simple as commenting out the following:

    #Begin custom attributes export

    Write-Host "Exporting " -NoNewline

    Write-Host "Custom Attributes" -ForegroundColor Green

    Write-Host " "

    $startdir = ".\$SourcevCenter\$Cluster\"

    $exportfile = "$startdir\attributes_export_vm.csv"

    $vms = Get-Cluster  $Cluster | Get-VM

    $Report =@()

        foreach ($vm in $vms) {

            $row = "" | Select Name, Notes, DR, "DR Value", DRStorage, "DRStorage Value"

            $row.name = $vm.Name

            $row.Notes = $vm.Notes

            $customattribs = $vm | select -ExpandProperty CustomFields

            $row.DR = $customattribs[0].Key

            $row."DR Value" = $customattribs[0].value

            $row.DRStorage = $customattribs[1].Key

            $row."DRStorage Value" = $customattribs[1].value 

            $Report += $row

        }

    $report | Export-Csv "$exportfile" -NoTypeInformation

    #End custom attributes export

    #Begin import of virtual machine custom attributes

    Write-Host " "

    Write-Host "Importing" -ForegroundColor Green -NoNewline

    Write-Host " VM custom attributes"

    Write-Host " "

    $startdir = ".\$SourcevCenter\$Cluster\"

    $importfile = "$startdir\attributes_export_vm.csv"

    $NewAttributes = Import-Csv $importfile

    ForEach ($vm in $NewAttributes){

            if(!$vm."DR Value" -and !$vm."DRSTorage Value") { } else {

       Write-Host "Custom " -NoNewline

       Write-Host "attributes" -ForegroundColor Green -NoNewLine

       Write-Host " and " -NoNewline

       Write-Host "notes" -ForegroundColor Green -NoNewLine

       Write-Host " for " -NoNewline

       Write-Host $vm.Name -ForegroundColor Green -NoNewLine

       Write-Host " are being imported now..."

       Set-Annotation -Entity (get-vm $vm.Name) -CustomAttribute $vm.DR -Value $vm."DR Value" -confirm:$false

       Set-Annotation -Entity (get-vm $vm.Name) -CustomAttribute $vm.DRStorage -Value $vm."DRStorage Value" -confirm:$false

       Write-Host " "

    }

    }

    #End import of virtual machine custom attributes



  • 83.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jun 05, 2015 05:44 AM

    Without actually testing it, yes, that looks the parts handling the annotations.

    In fact, you only need to comment out the import part.



  • 84.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jun 08, 2015 01:30 PM

    Let me take a deeper look at your transcript, but a couple options you have are to just comment out certain sections that you are having trouble with or adjust the error reporting for that section.  Example.

    Commenting out:

     

    Adjusting error reporting for just a section:

    On the folder errors make sure you are not getting hit by duplicates.  Folders were the bane of my existence with the script as we use them and notes/annotations extensively.  Caused the most problems and greatly slowed down the migration of the cluster.

    Duplicate folder names that exist under the same vCenter - ie, the same folder name existing say in different datacenters under the same VC.



  • 85.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 20, 2015 01:20 PM

    I can confirm that the error I was getting was due to missing the roles on the destination vCenter Server. Once I added them the script ran fine



  • 86.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Apr 01, 2016 01:35 PM

    Hi,

    thank you for this amazing script. I am using the script to migrate from an old 5.1 vCenter to a brand new 6.0 vcenter.

    But I have some problems.

    The main one is that it take only the first line of the .csv file.

    The other problem is I get these kind of messages:

    Importing

    permissions for the folders, hosts, virtual machines, datacenter and cluster

    Exception calling "SetEntityPermissions" with "2" argument(s): "

    Required parameter entity is missing

    while parsing call information for method SetEntityPermissions

    at line 1, column 218

    while parsing SOAP body

    at line 1, column 207

    while parsing SOAP envelope

    at line 1, column 38

    while parsing HTTP request for method setEntityPermissions

    on object of type vim.AuthorizationManager

    at line 1, column 0"

    I am trying to understand where in the script the problem can be, but if you know it already, it will be be a real saver :smileyhappy:



  • 87.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jun 20, 2016 04:47 PM

    hey everybody.  This thread has been stagnant for some time, but dusting off the old script for our migration from 5.5 to 6.0 and I'll be posting any improvements here.  I'm definitely going to try and get our teams away from using folders and replacing those with tags as it really slows down the migration script.



  • 88.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jun 21, 2016 05:14 AM

    If I may suggest, make the update an entry under Documents instead.

    It gives you versioning!

    Long threads are not really handy to find information



  • 89.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jun 21, 2016 12:30 PM

    Good suggestion.  Are you referring to a location in the VMTN website?  Never used documents here before.



  • 90.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Jun 22, 2016 04:39 AM

    Yes, at the top of the page you have the tabs Discussion and Documents.

    It's under Documents.



  • 91.  RE: Script to migrate cluster from one vCenter to another vCenter

    Posted Mar 24, 2017 01:22 PM

    Hi! Does the script run fine for 5.5 to 6.0?

    Thanks in advanced.