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.
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).
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
Is this taking place during the folder import section and can you provide an example of how your folder tree is laid out?
Thank you. This time there are no errors and the output.csv is filled with the folder structure...
I'm getting the same error with the latest version. Looks like I am a victim of my own poor, version control . 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.
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!
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.
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"
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
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.
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"
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.
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!
Anytime. Are you Czech? If so, I'll do all I can to help you as I'm 50% Czech!!
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?
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 traffi...