The script removes object from all groups whose name starts with a specific value. To execute the script, create a business rule, custom command or scheduled task configured for the required obejct type.
Parameters:
- $groupNameStartsWith - Specifies the value group names should start with.
- $pipelined - Specifies whether to pass the update through the Adaxes pipeline (e.g. to trigger business rules).
PowerShell
$groupNameStartsWith = "ABC-" # TODO: modify me
$pipelined = $True # TODO: modify me
# Get direct group membership.
$directGroupGuidsBytes = $Context.TargetObject.GetEx("adm-MemberOfGuid")
# Search parameters
$searcher = $Context.CreateGuidBasedSearcher($directGroupGuidsBytes)
$searcher.Criteria = New-AdmCriteria "group" -Expression {cn -startsWith $groupNameStartsWith}
try
{
# Execute search.
$searchIterator = $searcher.ExecuteSearch()
$searchResults = $searchIterator.FetchAll()
# Remove target object from greoups.
foreach ($searchResult in $searchResults)
{
$group = $Context.BindToObjectBySearchResultEx($searchResult, $pipelined)
$group.Remove($Context.TargetObject.AdsPath)
}
}
finally
{
# Release resources
if ($searchIterator){ $searchIterator.Dispose() }
}