Site icon Grzegorz Kulikowski

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.
[sourcecode language=”powershell”]
$myvmid=(get-vm ‘myvm’).id
(get-view -id $myvmid).UpgradeVM_Task(‘vmx-08’)
[/sourcecode]
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 😉
[sourcecode language=”powershell”]
$id=(get-vm ‘myvm’).id
$vmview=get-view -id $id
$param = @($null)
$vmview.gettype().GetMethod("UpgradeVM_Task").Invoke($vmview,$param)
[/sourcecode]
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)