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
- Managing security roles
- Binding to Adaxes-specific objects
- Managing Adaxes-specific objects
- IADs
- Online script repository