Adding roles with privileges from powercli

by Grzegorz Kulikowski

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.

You may also like

3 comments

Anonymous November 28, 2012 - 12:25 am

Your code is wrong. There is no -id param…

Reply
psvmware November 28, 2012 - 12:39 am

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

Reply
Wojciech Marusiak March 11, 2013 - 3:51 pm

This solution worked for me. I am using ESXi 5.1

Reply

Leave a Reply

Chinese (Simplified)EnglishFrenchGermanHindiPolishSpanish
Streaming live on Twitch right now.
CURRENTLY OFFLINE