I am trying to rename some of the roles with sample, to get rid of the sample part and later i want to customize the priviliges.
I look on the SDK at UpdateAuthorizationRole, but i doesn't work as i expected.
Who has an clue?
Below is the snipppet i am trying to get working:
$authMgr = Get-View AuthorizationManager
$rootid = Get-Folder -norecursion | Get-View
$ARR_ROLES = $authMgr.RoleList
foreach ($role in $ARR_ROLES)
{
if ($role.info.label -match "(sample)")
{
$ROLEID = $role.id
$OLD_LABEL = $role.info.label
$NEW_LABEL = $OLD.Replace("(sample)", "")
$authMgr.UpdateAuthorizationRole($oordid.moref, $ROLEID, $NEW_LABEL)
}
}
It'll be easier to use Get/[Set-VIRole|http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Set-VIRole.html] cmdlets.
If you still want to use UpdateAuthorizationRole SDK method you need to pass privileges list as third parameter. $rootId is not valid value for UpdateAuthorizationRole parameter.
$authMgr.UpdateAuthorizationRole($ROLEID, $NEW_LABEL, $PRIVILEGES)
Hi Rob,
I have to agree with Yasen, it's much easier with the Set-VIRole cmdlet.
Get-VIRole | where {$_.Name -match "(sample)"} | %{$_ | Set-VIRole -Name $_.Name.Replace("(sample)","").TrimEnd(" ")}
Your UpdateAuthorizationRole script had a few typos I'm afraid.
This should work
$authMgr = Get-View AuthorizationManager $rootid = Get-Folder -norecursion | Get-View $ARR_ROLES = $authMgr.RoleList foreach ($role in $ARR_ROLES) { if ($role.info.label -match "(sample)") { $ROLEID = $role.roleid $OLD_LABEL = $role.info.label $NEW_LABEL = $OLD_LABEL.Replace("(sample)", "") $authMgr.UpdateAuthorizationRole($ROLEID, $NEW_LABEL, $role.Privilege) } }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks guys.
I will give the get-virole and set-virole a chance.
I will keep the thread updated.
The set-virole and get-virole cmdlets are working perfectly.