I have a very large powershell script I created some time ago to clone our production servers into a development environment and configure them for use in vShield isolated development networks.
We have recently updated our vSphere 5 environment to vSphere 6 and changed the architecture around.
Previously with vSphere 5 we had a single vCenter server that was managing our two datacenters by itself.
With the new vSphere 6 design we have a PSC and VCSA server at each datacenter working in a single SSO domain.
The first thing I have done with my cloning script is to update the vcenter reference to an array of both servers so I connect to both VCs at once.
This allows me to see and manage VM guests from both vCenters so get-vm works to see the source guest.
The problem though is that when I try to clone a VM from one datacenter to the other the command fails as it cannot find the VM to clone.
# Virtual Centre server or VM host to connect to
$aryVIServer = @("vc01.domain.com", "vc02.domain.com")
# Load VMware environment
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
$VIServer = Connect-VIServer $aryVIServer
# Server cluster group to deploy to
$strVMCluster = "Bubbles"
# Define name of new server including environment prefix
$vmName = "$($envPrefix)-$($CloneServer)"
# Select Host with least memory consumption
$selectedHostObj = Get-VMHost -Location $strVMCluster | Sort-Object -Property MemoryUsageGB | Select-Object -First 1
# Select folder to place VM guest into
$folderObj = Get-Datacenter -Cluster $strVMCluster | Get-Folder $selectedBubble
# Select datastore with most available space
$selectedDatastoreObj = Get-DataStore -VMHost $selectedHostObj | Sort-Object -Property FreeSpaceGB -descending | Select-Object -First 1
# Clone new VM from running Server
$newVM = New-VM -Name $vmName -VM $CloneServer -VMHost $selectedHostObj -Datastore $selectedDatastoreObj -DiskStorageFormat "Thin" -Location $folderObj -Confirm:$false
This used to work fine when there was a single VC but of course is failing now with two.
The only difference so far is the change of VCs. We are still using the exact same hosts running ESXi 5.0 in the same location in separate datacenters.
Oh and I am now using powercli 6.3 R1 instead of 5.5 R1.
I expect this type of process should work fine and I will just need a different command for cloning the VMs now?