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 :
[sourcecode language=”powershell”]
$privs_for_role=@(
‘System.Anonymous’,
‘System.View’,
‘System.Read’)
New-VIRole -Name custom_role1 -Privilege (Get-VIPrivilege -id $privs_for_role)
[/sourcecode]
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.
Adding roles with privileges from powercli
previous post
3 comments
Your code is wrong. There is no -id param…
Hi Anonymous, can you tell what’s wrong when you are trying to create roles in above way? I can assure you that Get-VIprivilege has id parameter . Get-help Get-viprivileges -full
‘-Id : Specify the Ids of the privileges you want to retrieve.’
If you are running 5.x
http://www.vmware.com/support/developer/PowerCLI/PowerCLI50/html/Get-VIPrivilege.html
This solution worked for me. I am using ESXi 5.1