Upgrade virtual machine hardware using powercli


Now, i know that there are some examples in internet about this but they were not working for me for some reason(still don’t know why).
UpgradeVM_Task SDK ref
So in order to upgrade vmware hardware version you have to execute method called UpgradeVM_Task from virtual machine object.

$myvmid=(get-vm 'myvm').id
(get-view -id $myvmid).UpgradeVM_Task('vmx-08') 

If you want to upgrade to version 7, then you have to use ‘vmx-07’. I am running this against vsphere 5 and it works very well. Now, reading manual it says:
Regarding the ‘Version’ parameter:
“If specified, upgrade to that specified version. If not specified, upgrade to the most current virtual hardware supported on the host.”
But if you will give $null or “” , or nothing, it will just not work. I hope i will get some more information why it behaves like this.
UPDATE 😉

$id=(get-vm 'myvm').id
$vmview=get-view -id $id
$param = @($null)
$vmview.gettype().GetMethod("UpgradeVM_Task").Invoke($vmview,$param)

This will run upgrade_VM_Task method without specifying the version string. It took me some time to figure this out 😉
$vmview.gettype().GetMethod(“UpgradeVM_Task”).GetParameters()

ParameterType : System.String
Name : version
DefaultValue :
RawDefaultValue :
Position : 0
Attributes : None
Member : VMware.Vim.ManagedObjectReference UpgradeVM_Task(System.String) -> 1 parameter

the parameter should be an array of 1 null here
$param=@($null)
as per
Invoke(System.Object obj, System.Object[] parameters)

Advertisements

5 thoughts on “Upgrade virtual machine hardware using powercli

  1. Very nice! Thank you. This is what I was looking for.
    One more questing: is there an option to schedule/plan the hardware upgrade to be executed at next reboot. I want to make a script that runs through all virtual machines and upgrade them without shutting down the guest right now. e.g. -NoReboot like upgrading vmware tools.
    Thank you!
    Matthias

  2. hi Matthias, from what i know there is no possibility like this. You can only upgrade vmware tools when there is power cycle.
    If you are doing power cycles with scripts, then you might add the vm hw upgrade into that script.

  3. I too was looking for a script that could schedule the upgrade, it must be possible as there is an option to do just that in the webclient.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s