Returns the role assignment for a specific role for this user.


IRoleAssignment GetUserRoleAssignment(IRole role)


Specify the following parameter when using this method:

Parameter Description


The role for which you want the role assignment.

Return value

The role assignment that associates this user with the specified role. Returns null if none exists.


GetUserRoleAssignment throws an ArgumentNullException if you pass null for the role parameter.


The following code sample illustrates using GetUserRoleAssignment in a script:

// Create a CIMS object to interact with AD'
ICims cims = new Cims();
// Note the lack of the cims.connect function.'
// By default, this application will use the connection to the domain controller
// and existing credentials from the computer already logged in.
IHierarchicalZone objZone =
cims.GetZoneByPath("cn=" + strZone + "," + strContainerDN) as IHierarchicalZone;
IUser objUser = cims.GetUserByPath(strUser);
if (objUser == null)
    Console.WriteLine("User " + strUser + " does not exist.");
IHierarchicalUser objUnixUser = objZone.GetUserUnixProfile(objUser) as IHierarchicalUser;
if (objUnixUser == null)
    objUnixUser = objZone.AddUserPartialProfile(strUser);
IRole objRole = objZone.GetRole(strRoleName);
if (objRole == null)
    Console.WriteLine("Role " + strRoleName + " does not exist.");
IRoleAssignment objAsg = objUnixUser.GetUserRoleAssignment(objRole);
if (objAsg == null)
    Console.WriteLine("Role assginment does not exist.");
    Console.WriteLine("Role " + strRoleName + " was successfully removed from user " 
      + strUser);