Search AD except this OU

This topic contains 2 replies, has 2 voices, and was last updated by  Jeff Taylor 1 week, 3 days ago.

  • Author
  • #104144

    Jeff Taylor

    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

    I Like Cheese

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

You must be logged in to reply to this topic.