Search AD for users that fall under an OU named like

Welcome Forums General PowerShell Q&A Search AD for users that fall under an OU named like

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years, 2 months ago.

  • Author
  • #6308

    Points: 0
    Rank: Member

    by cfritzy at 2013-03-22 06:29:12

    I have some OU's under more location specific OU's in Active Directory called "ScreenSaverPolicyException" that we drop users into to bypass a screensaver policy we have in place. Unfortunately, I have about 69 of these "ScreenSaverPolicyException" OU's that I am trying to report on. I know I can use the Get-ADUser cmdlet to retrieve the information from a specific OU but I am trying to see if I can search AD with one cmdlet to try and find any in an OU named "like" "ScreenSaverPolicyException". Not sure if I can do a search on any OU named "like" or not. Any help would be appreciated.

    by MasterOfTheHat at 2013-03-22 09:45:39

    Since you can't filter using -like on DistinguishedName, you'll have to grab all of the "ScreenSaverPolicyException" OUs and then get all of the users within each of those OUs. Something like:
    Get-ADObject -Filter '(ObjectClass -eq "organizationalUnit") -and (Name -like "ScreenSaverPolicyException")' -SearchBase "DC=domain,DC=com" |
    ForEach-Object { Get-ADUser -SearchBase $_.DistinguishedName -Filter * }

    by mjolinor at 2013-03-28 15:53:37

    This seems to work:

    Get-ADOrganizationalUnit -Filter "Name -like '*ScreenSaverPolicyException*'"

The topic ‘Search AD for users that fall under an OU named like’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort