Hi Everyone,
I have written a PowerShell script to move windows patched VM from one vCenter 6.0 to another vCenter 6.0 using vSphere PowerCLI and I was successfully able to move, please find the working script below
# Using ovftool to export a vm as an ovf template
$ovftool = "C:\Program Files\VMware\VMware OVF Tool\ovftool.exe" # If the ovftool.exe is not in your path, you need to specify the full path here.
$sourceVM = 'xxxxxxxx'
$sourceVIServer = 'xxxxxxxx'
$targetVIServer = 'xxxxxxxx'
$targetDatacenter = 'xxxxxxxx'
$sourceNetwork = 'xxxxxxxx' # This is the portgroup that the VM is currently on.
$targetNetwork = 'xxxxxxxx' # This is the portgroup that you want the VM placed onto.
$targetCluster = 'xxxxxxxx'
$targetDatastore = 'xxxxxxxx'
Connect-VIServer $sourceVIServer
Connect-VIServer $targetVIServer
$VIServers = @{
$DefaultVIServers[0].name = $DefaultVIServers[0];
$DefaultVIServers[1].name = $DefaultVIServers[1]
$sourceVMMoref = (get-vm $sourceVM -Server $VIServers[$sourceVIServer]).extensiondata.moref.value
echo "sourceVIServer = $($VIServers.$sourceVIServer)"
$sourceSession = Get-View -server $VIServers.$sourceVIServer -Id sessionmanager
$sourceTicket = $sourceSession.AcquireCloneTicket()
echo "targetVIServer = $($VIServers.$targetVIServer)"
$targetSession = Get-View -server $VIServers.$targetVIServer -Id sessionmanager
$targetTicket = $targetSession.AcquireCloneTicket()
$sourceTicket = "--I:sourceSessionTicket=$($sourceTicket)"
$targetTicket = "--I:targetSessionTicket=$($targetTicket)"
$datastore = "--datastore=$($targetDatastore)"
$network = "--net:$($sourceNetwork)=$($targetNetwork)"
$source = "vi://$($sourceVIServer)?moref=vim.VirtualMachine:$($sourceVMMoref)"
$destination = "vi://$($targetVIServer)/$($targetDatacenter)/host/$($targetCluster)/"
echo $datastore $network $sourceTicket $targetTicket $source $destination
& $ovftool $datastore $network $sourceTicket $targetTicket $source $destination
Furthermore, our intention is to move VM from vCenter server 6.0 to vCenter server 5.1 however there is a VM hardware version conflicts between two different versions of vCenter server in our environment, but having said that I tried using following command which I saw from the VMware community for the downgrading the VM hardware version during the conversion
./ovftool --maxVirtualHardwareVersion=09 "/Users/cman/Documents/ABC.vmx" "/Users/cman/Documents/VM/ABC.ovf"
Unfortunately it didn't work for me and I am stuck here.
Please help to advise on this or probably is there any command to downgrade the VM hardware version from 11 to 9 during the conversion using ovf tool
Much appreciate your help
Thanks
Vignesh
Did you already try the --lax parameter?
It relaxes the HW version verification.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Thanks for your prompt reply,
Actually I didn't try using --lax parameter
Wondering whether I could be able to run this parameter on vSphere PowerCLI
If yes, what would be the syntax
Kindly advise
Thanks
It;s a parameter you add on the call to ovftool.exe.
./ovftool.exe --lax
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
I tried using the below command from my above script
& $ovftool --lax $datastore $network $sourceTicket $targetTicket $source $destination
It failed
Please advise
Thanks
Would you mind posting the error message?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Thanks for your reply
Error: OVF Package is not supported by target:
- Line 26: Unsupported hardware family 'vmx-11'.
Completed with errors
FYI, the source VM's HW version is vmx-11 running on vCenter server version 6.0 and target vCenter server is running on version 5.1 supports vmx-9
The script is as follows
# Using ovftool to export a vm as an ovf template
$ovftool = "C:\Program Files\VMware\VMware OVF Tool\ovftool.exe" # If the ovftool.exe is not in your path, you need to specify the full path here.
$sourceVM = 'xxxxxxxx'
$sourceVIServer = 'xxxxxxxx'
$targetVIServer = 'xxxxxxxx'
$targetDatacenter = 'xxxxxxxx'
$sourceNetwork = 'xxxxxxxx' # This is the portgroup that the VM is currently on.
$targetNetwork = 'xxxxxxxx' # This is the portgroup that you want the VM placed onto.
$targetCluster = 'xxxxxxxx'
$targetDatastore = 'xxxxxxxx'
Connect-VIServer $sourceVIServer
Connect-VIServer $targetVIServer
$VIServers = @{
$DefaultVIServers[0].name = $DefaultVIServers[0];
$DefaultVIServers[1].name = $DefaultVIServers[1]
$sourceVMMoref = (get-vm $sourceVM -Server $VIServers[$sourceVIServer]).extensiondata.moref.value
echo "sourceVIServer = $($VIServers.$sourceVIServer)"
$sourceSession = Get-View -server $VIServers.$sourceVIServer -Id sessionmanager
$sourceTicket = $sourceSession.AcquireCloneTicket()
echo "targetVIServer = $($VIServers.$targetVIServer)"
$targetSession = Get-View -server $VIServers.$targetVIServer -Id sessionmanager
$targetTicket = $targetSession.AcquireCloneTicket()
$sourceTicket = "--I:sourceSessionTicket=$($sourceTicket)"
$targetTicket = "--I:targetSessionTicket=$($targetTicket)"
$datastore = "--datastore=$($targetDatastore)"
$network = "--net:$($sourceNetwork)=$($targetNetwork)"
$source = "vi://$($sourceVIServer)?moref=vim.VirtualMachine:$($sourceVMMoref)"
$destination = "vi://$($targetVIServer)/$($targetDatacenter)/host/$($targetCluster)/"
echo $datastore $network $sourceTicket $targetTicket $source $destination
& $ovftool --lax $datastore $network $sourceTicket $targetTicket $source $destination
Please advise
Much appreciate your help
Thanks
So it seems the --lax option doesn't fix this.
You have a few options (see for example here).
The easiest to automate imho would be the one using the OVF Tool.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for your reply,
Wondering If in case vmx file gets corrupted, because we are automating this task in the production environment
Please advise
Much appreciate your help once again
Use precautions, like you always should.
Some guidelines:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, will test and let you know the outcome