PSxVCvMotion - Cross vCenter vMotion
PSxVCvMotion
This a Powershell / PowerCLI module for automating Cross vCenter vMotion. It is build to help migrate a lot of VM with heterogeneous configurations. By default it will assume that configurations are the same between the source and target vCenter. Optionnaly you can define targets for specifics items (portgroups, datastores).
The parameters needed for the vMotions are stored inside of a .ps1
file. They will be automatically tested before starting any vMotion.
This module is build with the modern and open sourced Powershell's tools Pester and PSake.
Special Thanks
A big shout out to William Lam and Kyle Ruddy for there blog articles about cross vCenter vMotion:
- Cross vCenter Server operations (clone / migrate) between versions of vSphere 6.x
- Spotlight on the Move-VM Cmdlet including PowerCLI 6.5 Enhancements
Known limitations
- You can only start vMotion between clusters.
- There's no check to test if resources are available (CPU, RAM and storage).
Instructions
Install the module
#Automated installation (Powershell 5):
Install-Module PSxVCvMotion -Scope CurrentUser
# Or manual setup
# Download the repository
# Unblock the zip
# Extract the PSxVCvMotion folder to a module path (e.g. $env:USERPROFILE\Documents\WindowsPowerShell\Modules\)
# Import the module
Import-Module PSxVCvMotion #Alternatively, Import-Module \\Path\To\PSxVCvMotion
# Get commands in the module
Get-Command -Module PSxVCvMotion
Run the script
- Edit or create a config file.The file need to be created with the
.ps1
extension. An example is available in \Path\To\PSxVCvMotion\Configs\Config.ps1 - Run the script in test mode.
> Invoke-xVCvMotion -Config \\Path\To\Config.ps1
- If everything works well, start the migration by adding the Migrate parameter.
> Invoke-xVCvMotion -Config \\Path\To\Config.ps1 -Migrate
Configuration file
An example is available in \Path\To\PSxVCvMotion\Configs\Config.ps1.
Here is a annotated version of the file:
$cfg = @{} #Do not modify this line
#### MANDATORY PARAMETERS
# Informations about the source vCenter
$cfg.sourcevc = @{
vc = 'srv-vcenter-01.example.com'
user = 'administrator@vsphere.local'
password = 'VMware1!'
}
# Information about the destination vCenter
$cfg.destinationvc = @{
vc = 'srv-vcenter-02.example.com'
user = 'administrator@vsphere.local'
password = 'VMware1!'
}
# Cluster translation table
# List of source and destination clusters
# You can provide only one line
$cfg.cluster = @(
@{source = 'CLUSTER01' ; destination = 'CLUSTER02'}
)
# List of VM matching the specified pattern and excluded VMs
# vm = '*' -> All VM selected
# vm = 'TEST*' -> All VM who's name starts with TEST
$cfg.vm = @{
scope = '*'
exclusion = @('VM01','VM02')
}
#### OPTIONAL PARAMETERS
# Portgroup translation table
# List of source and destination portgroups
# If the source portgroup is not on the list, the script will look at a destination portgroup with the same name
$cfg.portgroup = @(
@{source = 'PORTGROUP01'; destination = 'PORTGROUP03'}
@{source = 'PORTGROUP02'; destination = 'PORTGROUP04'}
)
# Datastore translation table
# List of source and destination datastores
# If the source datastore is not on the list, the script will look at a destination datastore with the same name
# If the VM has multiple datastore, the first one is selected
# Selecting a datastore cluster as destination is not supported
$cfg.datastore = @(
@{source = 'DATASTORE01'; destination = 'DATASTORE04'}
@{source = 'DATASTORE02'; destination = 'DATASTORE05'}
@{source = 'DATASTORE03'; destination = 'DATASTORE06'}
)
To Do
- Add possibility to select specifics VMHosts
- Add possibility to run vMotion asynchronously
- Add logs
Thanks for this great script, just the script I was looking for. This would make my job so easy.
When I run Get-Command -Module PSxVCvMotion, I get Invoke-xVCvMotion and Move-xVCvMotion.
Whats the difference and use case between Invoke and Move.
Thanks,
-Naga
Thanks for the feedback! Invoke-xVCvMotion is the command you want to use. The other one is used internally, I shouldn't have published it.
Regards,
Erwan
I just found this Post & Love your Script!
Is it possible to put in an exclusive list of VMs instead of using selected pattern?
I have a really complicated environment with multiple vDS's and we also use PVLANs, was trying to use this script to migrate a VM on a PVLAN to another vCenter, but I keep getting the following error.
[+] Source portgroup NetApp-stg-iso exists 2ms
[+] Destination portgroup NetApp-stg-iso exists 2ms
[-] If source portgroup is a vds, destination can't be a vss 12ms
Expected $false, but got $true.
94: ($sourcePortgroup.ExtensionData.Key -like 'dvportgroup-*') -and ($Destinationportgroup.ExtensionData.Key -notlike 'dvportgroup-*') | Should Be $False
at <ScriptBlock>, C:\Users\Admin\Documents\WindowsPowerShell\Modules\PSxVCvMotion\1.0.0\Tests\Pre.Tests.ps1: line 94
Any help would be really appreciated
Thanks
Rahul
Executing Connection
Error: 11/22/2019 9:13:32 AM:
At C:\Users\Richard\Documents\WindowsPowerShell\Modules\PSake\4.9.0\public\Invoke-Task.ps1:108 char:29 + & $task.Action + ~~~~~~~~~~~~~~ [<<==>>] Exception: Error while connecting to the source vCenter.
Build cannot continue!
How does the script connect to the vcenter?
Executing Connection
Error: 11/22/2019 9:13:32 AM:
At C:\Users\Richard\Documents\WindowsPowerShell\Modules\PSake\4.9.0\public\Invoke-Task.ps1:108 char:29 + & $task.Action + ~~~~~~~~~~~~~~ [<<==>>] Exception: Error while connecting to the source vCenter.
Build cannot continue!
How does the script connect to the vcenter?
Move-VM -VM DA_1018_RC_1 -Destination esx67.xxx.lab -NetworkAdapter Network adapter 1 Network adapter 2 -PortGroup -Datastore Datastore-V67. Its not emulating the portgroup names from the config.ps1
Is this tool obsolete?