AddUserRoleAssignment

Adds a user role assignment to the user profile.

Syntax

IRoleAssignment AddUserRoleAssignment()

Return value

An empty user role assignment object. This role assignment is not stored in Active Directory until you call the RoleAssignment:[Commit](../computerrole/commit.md) method.

Discussion

This object is not saved to Active Directory until you set at least one property value and call the Commit method.

Example

The following code sample illustrates using AddUserRoleAssignment in a script:

...  
IHierarchicalUser objUserUnixProfile = (IHierarchicalUser)
objZone.GetUserUnixProfile(objUser);  
if (objUserUnixProfile == null)  
{  
    // New user for the zone
    objUserUnixProfile = objZone.AddUserPartialProfile(strUser);  
}  
IRole objRole = objZone.GetRole(strRole);  
if (objRole == null)  
{  
    Console.WriteLine("Role " + strRole + " does not exist.");  
    return;  
}  
IRoleAssignment asg = objUserUnixProfile.GetUserRoleAssignment(objRole);  
if (asg != null)  
{  
    Console.WriteLine("Assignment already exist.");  
    return;  
}  
else  
{  
    // assigning role to user
    asg = objUserUnixProfile.AddUserRoleAssignment();  
    asg.Role = objZone.GetRole(strRole);  
    asg.Commit();  
    Console.WriteLine("Role " + strRole + " was successfully assigned to " + strUser
        \+ ".");  
}  
...