4 Replies Latest reply on Jun 10, 2010 2:39 AM by RobMokkink

    UpdateAuthorizationRole

    RobMokkink Expert

      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)

                          }

                }

        • 1. Re: UpdateAuthorizationRole
          ykalchev Expert
          VMware Employees

          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)
          

           

          1 person found this helpful
          • 2. Re: UpdateAuthorizationRole
            LucD Guru
            User ModeratorsCommunity WarriorsvExpert

            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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
            1 person found this helpful
            • 3. Re: UpdateAuthorizationRole
              RobMokkink Expert

              Thanks guys.

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

               

              I will keep the thread updated.

              • 4. Re: UpdateAuthorizationRole
                RobMokkink Expert

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