The issue with the query is due to how the -or
operator is evaluated, which could be causing incorrect results. You need to group your conditions carefully to ensure that each condition pair (job ID and department number) is correctly evaluated together.
Here's how you can adjust your query to make sure that you're pulling the correct users:
((userAccountControl -eq 512) -and ((departmentNumber -eq 10 -and extensionAttribute1 -eq '123') -or (departmentNumber -eq 11 -and extensionAttribute1 -eq '124')))
This ensures that the condition for departmentNumber
and extensionAttribute1
are grouped together correctly for each case.
The parentheses around each department/job ID combination force PowerShell to evaluate those pairs correctly.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin