Arne,
The scripts are ready. The below script will clean up Security Role Assignments created by your script. To run it:
-
Save the script to a file with the .ps1 extension on the computer where Adaxes service is installed. For example, you can name it fixassignments.ps1.
-
Log on to the computer with credentials of Adaxes default service administrator (the user that you specified when installing the service).
-
Launch Windows PowerShell. To do this:
- Press Win+R.
- Type powershell.exe
- Press Enter.
-
In the PowerShell Console, navigate to the folder where you saved the script file. For example, if you saved the file to C:\Scripts, type:
cd C:\Scripts
-
Run the script by executing the following line:
.\fixassignments.ps1 'My Role'
where:
- fixassignments.ps1 - is the name of the script file that you've created on step 1.
- My Role - is the name of the Security Role that you are having issues with.
The script:
param(
[Parameter(Mandatory=$true)]
[String]$roleName
)
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
# Connect to Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")
# Bind to Security Role
$securityRolesPath = $admService.Backend.GetConfigurationContainerPath( `
"AccessControlRoles")
$securityRolesPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
$securityRolesPath
$myRoleAdsPath = $securityRolesPathObj.CreateChildPath( `
"CN=$roleName")
$role = $admService.OpenObject($myRoleAdsPath, $NULL, $NULL, 0)
# Get all Assignments
$assignments = $role.Assignments
for ($i = 0; $i -lt $assignments.Count; $i++)
{
$assignment = $assignments.GetObject($i)
for ($j = $assignments.Count - 1; $j -gt $i; $j--)
{
# Check Trustee
$assignmentToCheck = $assignments.GetObject($j)
if ($assignmentToCheck.Trustee -ne $assignment.Trustee)
{
continue
}
# Compare Activity Scope Items
foreach ($itemToCheck in $assignmentToCheck.ActivityScopeItems)
{
$baseObjectGuidToCheck = [Guid]$itemToCheck.Get("adm-ScopeBaseObjectGuid")
$addNewItem = $True
foreach ($item in $assignment.ActivityScopeItems)
{
$baseObjectGuid = [Guid]$item.Get("adm-ScopeBaseObjectGuid")
if (($baseObjectGuidToCheck -eq $baseObjectGuid) -and ($itemToCheck.Inheritance -eq $item.Inheritance) -and ($itemToCheck.Exclude -eq $item.Exclude))
{
$addNewItem = $False
break
}
}
if (!($addNewItem))
{
continue
}
# Create Activity Scope Item
$scopeItem = $assignment.ActivityScopeItems.Create()
$scopeItem.BaseObject = $itemToCheck.BaseObject
$scopeItem.Type = $itemToCheck.Type
$scopeItem.Inheritance = $itemToCheck.Inheritance
$scopeItem.Exclude = $itemToCheck.Exclude
$scopeItem.SetInfo()
$assignment.ActivityScopeItems.Add($scopeItem)
}
$assignments.Remove($assignmentToCheck)
}
}
Write-Host "Operation completed"
Also, we've fixed your script file that created the mess, however, since it contains sensitive information, we won't publish it on the form. We've sent it over to you by e-mail. Check your inbox.