Automation

 View Only
  • 1.  UpdateAuthorizationRole

    Posted Jun 09, 2010 02:22 PM

    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)

    }

    }



  • 2.  RE: UpdateAuthorizationRole

    Broadcom Employee
    Posted Jun 09, 2010 03:14 PM

    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)
    



  • 3.  RE: UpdateAuthorizationRole

    Posted Jun 09, 2010 04:09 PM

    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



  • 4.  RE: UpdateAuthorizationRole

    Posted Jun 10, 2010 06:27 AM

    Thanks guys.

    I will give the get-virole and set-virole a chance.

    I will keep the thread updated.



  • 5.  RE: UpdateAuthorizationRole

    Posted Jun 10, 2010 09:39 AM

    The set-virole and get-virole cmdlets are working perfectly.