0 votes

Hi,

the script is only working for groups likeimage.png

A group with multiple values like here is not found: image.png

How to change the script to find them as well? I want to find all groups where the extensionAttribute5 is used with the value Permanent.

ago by (1.8k points)
0

Hello,

Sorry for the confusion, but we are not sure what exactly the issue is and the difference in criteria. Please, describe the desired and the actual behavior you are facing in all the possible details with live examples.

0

Hi,

based on the script shared previuosly I am able to find rule-based groups where (in my example) I look for extensionName5 is Permanent (1st screenshot).

However, the script is not finding a group where the value of property is Permanent or Apprenticeship.

0

Hello,

Sorry for the confusion, but we are not sure what exactly you mean. The criteria in both your screenshots are dedicated to users, not groups.

image.png

0

Hi, sorry, let me start from scratch

I have this report image.png

Parameters image.png

Script

$propertyName = "%param-PropertyName%"
$propertyValue = "%param-PropertyValue%"

try
{
    $groupCriteria = New-AdmCriteria -Type "group" -Expression {membershipType -eq "rule-based"}
    $Context.DirectorySearcher.AddCriteria($groupCriteria)

    $criteriaToCompare = New-AdmCriteria -Expression {$propertyName -eq $propertyValue}    
    $criteriaJsonToCompare = $criteriaToCompare.Item("*").Items.ToJson($null)
    $searchResultIterator = $Context.DirectorySearcher.ExecuteSearch()
    while ($Context.MoveNext($searchResultIterator))
    {
        $searchResult = $searchResultIterator.Current
        $group = $Context.BindToObjectBySearchResult($searchResult)

        foreach ($rule in $group.MembershipRules) 
        {
            if ($rule.Type -ne "ADM_BUSINESSUNITMEMBERSHIPTYPE_QUERY")
            {
                continue
            }

            $criteria = $rule.GetCriteria()

            if ($criteria.ToJson($NULL) | Select-String -Pattern $criteriaJsonToCompare -SimpleMatch)
            {
                $Context.Items.Add($searchResult)
                break
            }
        }
    }
}
finally
{
    if ($searchResultIterator) 
    { 
        $searchResultIterator.Dispose()
    }
}

If I run the report, I get only one rule based group image.png

This group has the following rule image.png

But, we have also some other rule based groups like with this rule image.png

This group is not found by the report/script.

Is there any chance to find also groups with the rule set of the second one?

My goal is: Find all rule base groups where the condition contains

extensionAttribute5 is Permanent

However we need also to find groups with rule

extensionAttribute5 is Permanent OR X OR Y

1 Answer

0 votes
ago by (302k points)

Hello,

Thank you for clarifying. The only option is to create each criteria you need to check in the script and compare with that of a group. Same like you do it now for a single criteria.

Related questions

0 votes
1 answer

Hello, we have a forest with two trees that hold one domain each. There is a default tree-root trust (transitive, two-way) between the top domains. Since both trees are in ... Sid S-1-5-10 were found". Any help would be appreciated, thank you! Regards HarryNew

asked Oct 8, 2020 by HarryNew (270 points)
0 votes
1 answer

If I have 2 Active Directory Security groups in my domain - Group A Group B Is it possible to create a report that shows only users who have membership in both groups? For ... Jane Doe is in Group A AND Group B she would be included in the resulting report.

asked May 11, 2020 by sirslimjim (480 points)
0 votes
1 answer

Hello, I'm trying to execute a custom command through a Powershell script, but I'm struggling to pass multiple values to an AD Object Picker parameter. ... , $NULL, $NULL, 0) $obj.ExecuteCustomCommand($command.CommandID, $commandArguments) Thanks in advance!

asked Nov 24, 2021 by KelseaIT (320 points)
0 votes
1 answer

Hello, I would like to use the 'Department Number' attribute during user creation, but on my form it allows the end user to add addition values? I'm using Property Patterns to ... the '+' symbol it lets me add multiple. Is there a way to remove this? Thanks

asked Oct 27, 2020 by bavery (250 points)
0 votes
1 answer

I was using this and it was working just fine. But now I get this error Method not found: 'Void Azure.Core.TokenRequestContext..ctor(System.String[], System.String, System. ... String, Boolean)'. Stack trace: at <ScriptBlock>, <No file>: line 5

asked Sep 20, 2024 by raphaelgagnon (40 points)
3,699 questions
3,383 answers
8,549 comments
549,737 users