We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script repository

Remove object from all groups whose name starts with a specific value

November 01, 2024 Views: 55

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).
Edit Remove
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() }
}
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers