Configuration
We have two vcenters that are linked and we can vMotion no problem using the GUI - but when using PowerCLI we run into issues in getting the system to migrate.
Vcenters
- vcsa1
- vcsa2
VM Name
- test-vm
The Storage and the Network are named the same on both systems
- IE Storage named: company_storage (Both on vcsa1 and vcsa2)
- the esxi hosts are different, but we have a Linux, Windows cluster configured on each of the vcsa's
- the Network is a distributed Switch with matching names on both vcsa's as well
Note: our names have pipes in them - for example COMPANY|ACI|VLAN###
Here is the code I am using and have been trying to modify (From Example 11 in the Link above)
$vc1 = 'vcsa1.company.com'
$vc2 = 'vccs2.company.com'
$MyVm = 'test-vm'
$cred = Get-Credential
### Connect to dc1-vcsa and dc2-vcsa
Connect-VIServer $vc1 -Credential $cred
Connect-VIServer $vc2 -Credential $cred
## Get VAriables from output after connecting to VCSAs
$vm = Get-VM $MyVm
$destinationCluster = Get-VM $MyVm | Get-Cluster | Select-Object -ExpandProperty Name
# Get destination datastore accessible to both vCenter Servers
$destinationDatastore = "pure_vm_prod"
# Get destination port group name or key
$PG = Get-VirtualPortGroup -VM $MyVm
$destinationPortGroup = "'(Get-VirtualPortGroup -VM $MyVm).Name'"
## Command to initiate Migration from DC1 to DC2
Move-VM -VM $vm -DestinationType Datastore -Datastore $destinationDatastore -PortGroup $destinationPortGroup -Server $vc2 -Credential $cred
When I echo out the variables it gives me the data, but returns the following error:
| "'(Get-VirtualPortGroup -VM test-migration).Name'" value of type
| "System.String" to type
| "VMware.VimAutomation.ViCore.Types.V1.Host.Networking.VirtualPortGroupBase".
I have tried several variations on this data - converting to string, escaping the output of the pipe characters, manually entering the correct name, adding the following example code to several of the variables:
"(Get-VirtualPortGroup -VM $MyVm).Name"