Forum Discussion

CSullivan55's avatar
CSullivan55
Copper Contributor
Aug 30, 2023
Solved

Get computer objects based on list of OUs

I have a query that will get OUs which block GP inheritance. I am not able to use get-adcomputer to search through that OU list. I can't find a way to get the -searchbase parameter to cycle through t...
  • LainRobertson's avatar
    Aug 31, 2023

    CSullivan55 

     

    Here's a very basic example.

     

    Get-ADObject -Filter { (objectClass -eq "organizationalUnit") -and (gPOptions -eq 1) } |
        ForEach-Object {
            Get-ADComputer -Filter * -SearchBase ($_.distinguishedName);
        }

     

    Note: If inheritance is blocked on one organisational unit, and then blocked again in a nested organisational unit, this could result in a computer being listed twice (once for each search).

     

    You could script your way around this but I've ignored this scenario in order to keep things basic.

     

    Cheers,

    Lain

Resources