Skip to content

Getting Security Roles assigned to a user

The following code sample retrieves a list of Security Roles assigned to a user.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $admService.OpenObject("Adaxes://$userDN", $NULL, $NULL, 0)

# Get DNs of the role assigmnents for the user
$roleAssignmentDNs = $user.Get("adm-AssignedRoleAssignments")

foreach($roleAssignmentDN in $roleAssignmentDNs)
{
    # Bind to the assignment object
    $assignment = $admService.OpenObject("Adaxes://$roleAssignmentDN", $NULL, $NULL, 0)

    # Get the DN of the Secyrity Role
    $roleDN = $assignment.Get("adm-AssignmentRole")

    # Bind to the Security Role
    $role = $admService.OpenObject("Adaxes://$roleDN", $NULL, $NULL, 0)

    Write-Host $role.Name
}

See also