Filtering Get-ADObject to with specific patterns and OU?

Welcome Forums General PowerShell Q&A Filtering Get-ADObject to with specific patterns and OU?

Viewing 1 reply thread
  • Author
    Posts
    • #251036
      Participant
      Topics: 27
      Replies: 28
      Points: 250
      Rank: Participant

      Hi All,

      How can I filter out or exclude some of the results of the Get-ADObject with the below Query?

      Script:

      Issues:
      1. When I add the Filter Enabled -eq $true, nothing is returned. How can I get only the enabled AD Objects?

      2. I wanted to exclude certain OU like ‘OU=Disabled Users

      3. If the name contains anything like the above $Exclusions

      Thank you in advance.

      • This topic was modified 1 month, 1 week ago by IT Engineer.
    • #251114
      Participant
      Topics: 0
      Replies: 81
      Points: 362
      Helping Hand
      Rank: Contributor

      Enabled is not an attribute of Get-ADObject output. You will need to look at UserAccountControl attribute instead if you are sticking with that cmdlet.

      You can use -not UserAccountControl -band 2 in place of Enabled -eq $true.

      Comparison operators for collections like -contains , -notcontains, -notin, and -in compare single strings to a collection.  Exact matches are required, i.e. no wildcards are allowed. If you want to do wildcard matching, consider using a regex operator like -notmatch. First you will need to use alternations ( |) to create the OR-like condition.

      Excluding an OU will likely require parsing the DistinguishedName value. I don’t believe that attribute is recognized in the -Filter so Where-Object must be used.

       

       

Viewing 1 reply thread
  • You must be logged in to reply to this topic.