Search AD except this OU

Welcome Forums DSC (Desired State Configuration) Search AD except this OU

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 months, 2 weeks ago.

  • Author
    Posts
  • #104144

    Participant
    Points: 0
    Rank: Member

    I have this search:

    Get-ADUser -filter {enabled -eq $true -and pwdLastSet -eq 0} -Properties mail |
        where {$_.mail -ne $null -and $_.DistinguishedName -ne "OU=DisabledUsers,DC=mycorp,DC=com"} | Measure-Object

    ...but it's still including accounts in the DisabledUsers OU.

    is my Operator incorrect or my Where-Object logic?

    Thank you

  • #104152

    Participant
    Points: 7
    Rank: Member

    maybe try:
    $_.DistinguishedName -notlike "*OU=DisabledUsers,DC=mycorp,DC=com"

    • #104153

      Participant
      Points: 0
      Rank: Member

      Thanks, that worked.

The topic ‘Search AD except this OU’ is closed to new replies.