Adding roles with privileges from powercli

This will be very quick and short one 😉
We can easily create a role within our VC using the new-virole cmdlet. Since it accepts the privilege IDs as an array we can first fill up our array with privileges and then give it to new-virole.
In order to see from which we can run get-viprivilege to get all of them first. If you already know which one to include :

New-VIRole -Name custom_role1 -Privilege (Get-VIPrivilege -id $privs_for_role)

the -Privilege accepts only privileges, so we first need to get them using get-viprivilege and giving id name so we will receive privilege object.


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.

$id=(get-vm 'myvm').id
$vmview=get-view -id $id
$param = @($null)

This will run upgrade_VM_Task method without specifying the version string. It took me some time to figure this out 😉

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
as per
Invoke(System.Object obj, System.Object[] parameters)