Hello All,
Working on a script to migrate VMs from a 6.0 vcenter to new 6.7 vcenter in different SSO domains. I'm reading the VM names, destination clusters, and datastores (if provided) from a .CSV file.
If a datastore isn't provided the script goes and find the datastore with most free space and see if it has enough to perform migration at the destination cluster.
I'm getting below error messages. This isn't making sense to me as i pass the name through as $vmToMigrate and it goes out into environment and get the object info and stores it in $vm prior to calling Move-VM cmdlet.
Borrowed main functionality from script posted here:Using PowerCLI to vMotion VM between different SSO domains · cloudmaniac.net
[quote]
Move-VM : 6/26/2019 9:15:33 PM Move-VM One or more objects are specified by name. There is no server list explicitly specified, so an attempt was made to determine a single server by the managed objects passed to the cmdlet as arguments. However the arguments
come from more than one server which makes it impossible to unambiguously select single server.
At C:\Users\***********\Desktop\scripts\Cross VC VMotion\xVmotion.ps1:110 char:10
+ $vm | Move-VM -Destination $destination -NetworkAdapter $networkAd ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (System.Collecti...1.VIConnection]:List`1) [Move-VM], ViServerConnectionException
+ FullyQualifiedErrorId : Core_ObnSelector_GetClientListFromCmdletParameters_AmbiguousServer,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM
Move-VM : 6/26/2019 9:15:34 PM Move-VM Destination container, datastore and portgroups must reside on the same vCenter Server.
At C:\Users\*******\Desktop\scripts\Cross VC VMotion\xVmotion.ps1:110 char:10
+ $vm | Move-VM -Destination $destination -NetworkAdapter $networkAd ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Move-VM], VimException
+ FullyQualifiedErrorId : Client20_VmHostServiceImpl_CheckMoveVmParameters_DifferentServer,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM
[/quote]
#Import CSV file list.
$vmlist = Import-Csv soggyblock.csv
####################################################################################
# Connect to vCenter Servers
Connect-ViServer -Server $SrcvCenter -User $SrcvCenterUserName -Password $SrcvCenterPassword -WarningAction Ignore | out-null
write-Host -foregroundcolor Yellow "`nConnected to Source vCenter..."
Connect-ViServer -Server $DstvCenter -User $DstvCenterUserName -Password $DstvCenterPassword -WarningAction Ignore | out-null
write-Host -foregroundcolor Yellow "Connected to Destination vCenter..."
####################################################################################
# Function GetPortGroupObject
function GetPortGroupObject {
Param(
[Parameter(Mandatory=$True)]
[string]$PortGroup
)
if (Get-VDPortGroup -Name $DstPortGroup -ErrorAction SilentlyContinue) {
return Get-VDPortGroup -Name $DstPortGroup
}
else {
if (Get-VirtualPortGroup -Name $DstPortGroup -ErrorAction SilentlyContinue) {
return Get-VirtualPortGroup -Name $DstPortGroup
}
else {
Write-Host "The PorGroup '$DstPortGroup' doesn't exist in the destination vCenter"
exit
}
}
}
function Drawline {
for($i=0; $i -lt (get-host).ui.rawui.buffersize.width; $i++) {write-host -nonewline -foregroundcolor cyan "-"}
}
#######################################################################################
# Main Script.
foreach ($vmToMigrate in $vmlist)
{
#Define variables to start vmotion.
$DstCluster = $vmToMigrate.'DstCluster'
$DstPortGroup = $vmToMigrate.'DstNetwork-1'
$DstDataStore = $vmToMigrate.'DstDataStore'
#If DstDatastore isn't defined in excel CSV document.find a datastore with enough space.
if(!$DstDataStore)
{
#Get datastore from the destination cluster with most free space.
$Datastore = Get-Cluster $vmToMigrate.DstCluster | Get-Datastore | Sort-Object -Property FreespaceGB -Descending:$true | Select-Object -First 1
#Calculate buffer to not fill DS beyond 75%. growth and snapshots.
$DSBuffer = $Datastore.CapacityMB * .75
#Calculate total used space in datastore.
$DSUsedSpaceGB = $Datastore.CapacityMB - $Datastore.FreeSpaceMB
#Calculate if this datastore has enough free space to place VM and not go beyond 75% full.
if($DSUsedSpaceGB + $vmToMigrate.'In Use MB' -gt $DSBuffer)
{
write-host "ERROR: No Datastore found with enough free space. Provision more storage to cluster"
Exit;
}
#If datastore has enough space and doesn't exceed the 75% buffer. Define the Destination Datastore.
else
{ $destinationDatastore =$Datastore.Name }
}
Else
{
$destinationDatastore = $vmToMigrate.DstDataStore
}
####################################################################################
# vMotion
$vm = Get-VM $vmToMigrate.VM
$destination = Get-VMHost -Location $DstCluster | Select-Object -First 1
$networkAdapter = Get-NetworkAdapter -VM $vmToMigrate.VM
$destinationPortGroup = GetPortGroupObject -PortGroup $DstPortGroup
$vm | Move-VM -Destination $destination -NetworkAdapter $networkAdapter -PortGroup $destinationPortGroup -Datastore $destinationDatastore | out-null
####################################################################################
# Display VM information after vMotion
write-host -foregroundcolor Cyan "`nVM is now running on:"
Drawline
Get-VM $vm | Get-NetworkAdapter | Select-Object @{N="VM Name";E={$_.Parent.Name}},@{N="Cluster";E={Get-Cluster -VM $_.Parent}},@{N="ESXi Host";E={Get-VMHost -VM $_.Parent}},@{N="Datastore";E={Get-Datastore -VM $_.Parent}},@{N="Network";E={$_.NetworkName}} | Format-List
}
Seen the error message, can you try adding the Server parameter on the cmdlets?
And point explicitly to the correct vCenter.
I wonder if the error message goes away or changes.
Btw, which PowerCLI are you using?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Could it be that you have a cluster or a datastore or a portgroup with the same name on both vCenters?
If yes, you can try adding the Server parameter on some cmdlets, to explicitly specify which vCenter a specific resource is on.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I had a similar thought and tested by making destination port group one that is only on destination vcenter. same error message.
Source Cluster:ServerAutomationPOC
Source VM Name: glog00pa00lv
Source datastore:T0-GP-XIO-02-DS003
Source portgroup: VLAN**52-vm-devtest03
Source Host:esx**pi68
Destination cluster: PDC-TierLAB01
Destination Datastore: PDC-TierLAB-DS002
Destination portgroup:VLAN3***-vmdata01
Destination Host:esx**ti12
Seen the error message, can you try adding the Server parameter on the cmdlets?
And point explicitly to the correct vCenter.
I wonder if the error message goes away or changes.
Btw, which PowerCLI are you using?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That got me past that error message.
changed below
[quote]
$vm | Move-VM -Destination $destination -NetworkAdapter $networkAdapter -PortGroup $destinationPortGroup -Datastore $destinationDatastore | out-null
[/quote]
to
[quote]
$vm | Move-VM -Destination $destination -NetworkAdapter $networkAdapter -PortGroup $destinationPortGroup -Datastore $destinationDatastore -Server $DstvCenter | out-null
[/quote]
Had to add $DstvCenter to function that get destination port group also. My Portgroups are identical across all my vcenter in the DC. Look like the below now.
[quote]
function GetPortGroupObject {
Param(
[Parameter(Mandatory=$True)]
[string]$PortGroup,
[string]$Server
)
if (Get-VDPortGroup -Name $DstPortGroup -ErrorAction SilentlyContinue) {
return Get-VDPortGroup -Name $DstPortGroup -Server $DstvCenter
}
else {
if (Get-VirtualPortGroup -Name $DstPortGroup -ErrorAction SilentlyContinue) {
return Get-VirtualPortGroup -Name $DstPortGroup -Server $DstvCenter
}
else {
Write-Host "The PorGroup '$DstPortGroup' doesn't exist in the destination vCenter"
exit
}
}
}[/quote]
VMware PowerCLI 11.3.0 build 13990089
Thanks for help!LucD