Here is another script that can be used in the If PowerShell script returns true condition.
The script allows group membership modification for group managers and Adaxes service administrators.
Import-Module Adaxes
$groupDN = "%distinguishedName%"
$initiatorDN = "%adm-initiatorDN%"
$managedByDN = "%managedBy%"
$Context.ConditionIsMet =$True
# Test whether the initiator is a service administrator
$configurationSetSettingsPath = $Context.GetWellKnownContainerPath("ConfigurationSetSettings")
$configurationSetSettings = $Context.BindToObject($configurationSetSettingsPath)
if ($configurationSetSettings.AdministratorManager.AmIAdministrator())
{
$Context.ConditionIsMet = $False;
}
else
{
# Test whether the group is managed by the intiator
if ($initiatorDN -eq $managedByDN)
{
$Context.ConditionIsMet = $False
}
else
{
$domainName = $Context.GetObjectDomain($initiatorDN)
foreach ($group in Get-AdmPrincipalGroupMembership $initiatorDN -Server $domainName -adaxesservice localhost)
{
if ($group.DistinguishedName -eq $managedByDN)
{
$Context.ConditionIsMet = $False
break
};
}
}
}
To use the script, add the Cancel this operation action to your Business Rule and add the If PowerShell script returns true condition for the action. Use the script in the condition.