Get-ADUser -Filter

Glenn Maxwell 12,871 Reputation points
2022-03-19T23:19:11.767+00:00

Hi All

i have below designation in our Company. I am trying to fetch all the users who has the words Product, Manager, Mgr in their Job Title or Description. i am trying the below queries but i am not getting correct list. Experts guide me

Manager Product ABC
ABC Product Manager
Product Manager ABC
ABC Manager Product
Manager Team Product
Product Team Manager

$List ="(title -like '*Product Manager*') -or (title -like '*Product Mgr*') or (Description -like '*Product Manager*) -or (Description -like '*Product Mgr*)
Get-ADUser -Filter $List -Properties DisplayName,title,Office,description |Select DisplayName,title,Office,description | Export-csv C:\temp\output.csv -Notypeinformation
Windows for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2022-03-20T14:52:17.787+00:00

    Try this as your filter string:

    "(title -like '*product*' -and (title -like '*manager*' -or title -like *mgr*)) -or (description -like '*product*' -and (description -like '*manager*' -or description -like *mgr*))"
    

    The reason your "-match" operator doesn't work is because it's not a supported operation. When composing filters on AD objects, think like you're composing a LDAP filter.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Glenn Maxwell 12,871 Reputation points
    2022-03-20T02:50:20.373+00:00

    its my typo mistaking while posting i am getting output but not accurate results.
    For example lets say the designation is Product Test Manager or it can be anything, if designation or title contains any words matching Product & Manager not just Product Manager i want to get that output. in my syntax i dont see it pulling Product Test Manager

    $List ="(title -like 'Product Manager') -or (title -like 'Product Mgr') or (Description -like 'Product Manager') -or (Description -like 'Product Mgr')
    Get-ADUser -Filter $List -Properties DisplayName,title,Office,description |Select DisplayName,title,Office,description | Export-csv C:\temp\output.csv -Notypeinformation

    0 comments No comments

  2. Glenn Maxwell 12,871 Reputation points
    2022-03-20T09:03:34.577+00:00

    I have used the below syntax i am getting error, lets say if the users designation is Manager, Product Team then i am unable to fetch users

    $List ="((description -Match '*Product|mgr|manager*') -or (title -Match '*Product|mgr|manager*'))"
    Get-ADUser -Filter $List -Properties DisplayName,title,Office,description |Select DisplayName,title,Office,description | Export-csv C:\temp\output.csv -Notypeinformation
    

    Get-ADUser : Error parsing query: ((description -Match 'Product|mgr|manager') -or (title -Match 'Product|mgr|manager'))' Error Message: 'Operator Not supported: -Match'
    at position: '98'.
    At line:2 char:1

    • Get-ADUser -Filter $Q -Properties DisplayName...
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : ParserError: (:) [Get-ADUser], ADFilterParsingException
    • FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADFilterParsingException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.