This 2 lines will upgrade virtual hardware in vm to version 8. it works, i tested it. But when i was writing it first, i wrote it like this:
Task was created , no error in powercli console. But error was displayed in VC, saying that this is impossible.
I read the guide about thie upgradeVM_task and it says:
|_this||ManagedObjectReference||A reference to the VirtualMachine used to make the method call.|
|version*||xsd:string||If specified, upgrade to that specified version. If not specified, upgrade to the most current virtual hardware supported on the host.|
So the parameter version is not needed becase of the " * " next to property version. It should assume vmx-08 by defalut as this is the newest version(esxi 5). This parameter version from what it says does not require $null , i can ommit it right ? OR this is another example that i should use get_type,get_method,invoke and somehow push $null to it ?
$vmview=get-view -id $id
$param = @($null)
.... 20 minutes of trying and finally did it
ParameterType : System.String
Name : version
Position : 0
Attributes : None
Member : VMware.Vim.ManagedObjectReference UpgradeVM_Task(System.String) -> 1 parameter
But this 1 parameter should be in array , so i i wanted to give $null, it should be $param=@($null)
Invoke(System.Object obj, System.Object parameters)
Can others confirm my thinking ?
You stumbled upon a known PowerShell problem.
When a parameter for a SDK method is defined as type [string], you can't use a $null value to indicate that the parameter is not present.
The only workaround is the Invoke method which will allow you to pass the method parameters as an array. And that way you can use $null to specify the absence of a parameter.