Script repository

Members of groups based on property value

Updated on: Jan 18, 2026, Views: 1391

Reports, Group membership

The script generates a report containing members of the groups that have a specific property set to a certain value. To execute the script, create a report with a custom column of the Directory object type. The report scope should include subordinates of a user.

Parameters

  • $namingParameter - the name of the parameter used to enter the value to search for. The name should be specified with the param- prefix.
  • $searchPropertyParameter - the name of the parameter of the Property picker type used to select the property for search. The name should be specified with the param- prefix.
$namingParameter = "param-groupNamePattern" # TODO: modify me
$searchPropertyParameter = "param-propertyName" # TODO: modify me

# Get parameter values.
$groupNameEnd = $Context.GetParameterValue($namingParameter)
$searchPropertyName = $Context.GetParameterValue($searchPropertyParameter)

# Search parameters
$criteria = New-AdmCriteria "group" -Expression {$searchPropertyName -contains $groupNameEnd}
$Context.DirectorySearcher.AddCriteria($criteria)
$Context.DirectorySearcher.VirtualRoot = $True

try
{
   # Execute search
   $searchResultIterator = $Context.DirectorySearcher.ExecuteSearch()
   $searchResults = $searchResultIterator.FetchAll()   
}
finally
{
   # Release resources
   if ($searchResultIterator) { $searchResultIterator.Dispose() }
}

if ($searchResults.Length -eq 0)
{
    return
}

# Get GUIDs of group members
$memberGuidsBytes = New-Object System.Collections.ArrayList
foreach ($searchResult in $searchResults)
{
   $group = $Context.BindToObjectBySearchResult($searchResult)
   try
   {
       $groupMemberGuidsBytes = $group.GetEx("adm-DirectMembersGuid")
   }
   catch
   {
       continue
   }
   $memberGuidsBytes.AddRange($groupMemberGuidsBytes)
}   

# Generate report
$searcher = $Context.CreateGuidBasedSearcher($memberGuidsBytes)
$Context.Items.Add($searcher)

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    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.