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

Members of groups based on property value

June 06, 2022 Views: 753

The script generates a report containing members of the groups that have a property with a specific value. To execute the script, create a report.

Parameters:

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

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

$Context.DirectorySearcher.AppendFilter("(&(objectCategory=group)($searchPropertyName=*$groupNameEnd*))")
$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
Leave a comment
Loading...

Got questions?

Support Questions & Answers