VMware Cloud Community
vickyshiv123
Enthusiast
Enthusiast

Move Windows Patched VM from one vCenter to another vCenter (ovftool) using vSphere PowerCLI

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

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership

Did you already try the --lax parameter?

It relaxes the HW version verification.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vickyshiv123
Enthusiast
Enthusiast

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

Reply
0 Kudos
LucD
Leadership
Leadership

It;s a parameter you add on the call to ovftool.exe.

./ovftool.exe --lax


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vickyshiv123
Enthusiast
Enthusiast

Hi,

I tried using the below command from my above script

& $ovftool --lax $datastore $network $sourceTicket $targetTicket $source $destination

It failed

Please advise

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership

Would you mind posting the error message?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vickyshiv123
Enthusiast
Enthusiast

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

Reply
0 Kudos
LucD
Leadership
Leadership

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.

  • extract the VMX from the OVF with the OVF Tool
  • edit the VMX, in other words change the HW version
  • Create a new OVF from the updated VMX with the OVF Tool


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vickyshiv123
Enthusiast
Enthusiast

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

Reply
0 Kudos
LucD
Leadership
Leadership

Use precautions, like you always should.

Some guidelines:

  • test, test, test your scripts!
  • make sure to have backups/snapshots before doing any changes
  • make a backup of the VMX file before doing any changes
  • make sure you have a fallback script/procedure (restoring the VMX backup copy, reverting to a snapshot, restoring a backup...)
  • when you ultimately go to production, run on a small subset of VMs to confirm the script is doing what you want it to do


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vickyshiv123
Enthusiast
Enthusiast

Thanks, will test and  let you know the outcome

Reply
0 Kudos