Get-AdComputer: Find Computers in OUs with PowerShell

Get-AdComputerFor today’s cmdlet, we’re going to focus on Get-AdComputer. Similar to one of the previous cmdlets of the day Get-AdUser, this cmdlet is it’s counterpart in the Active Directory module. Instead of retrieving user objects from Active Directory, this cmdlet finds computers in OUs.

The Get-AdComputer Filter Parameter

One way to use this cmdlet is to use the Filter parameter. We can use the Filter parameter to search for computers in Active Directory based on their name, for example.

Finding Computers in an OU

Perhaps we’re not necessarily concerned with their name but in what OU they’re in. Like the Get-AdUser cmdlet, this cmdlet has a SearchBase parameter we can use to limit the search only to an OU and all of its child OUs. Below I’m finding all of the domain controllers inside of my mylab.local’s Domain Controllers OU.

But what if you’ve got a ton of child OUs under the parent OU and you’d like to only get computers from Active Directory in that parent OU? In that case, we can use the SearchScope parameter. Below I’m using the 1 argument to only find computer objects in the immediate OU. I could have used 2 instead to define a “subtree” which would recursively look through all of the child OUs as well.

If you’re good at LDAP filters, you can also use the LDAPFilter parameter on Get-ADComputer. The LDAP filter allows you to use LDAP syntax to hone in on exactly the computer you’re looking for. LDAPFilter can be used with the SearchBase parameter or by itself. Below, I’m using the LDAP filter to find all computers that start with F and are in the Domain Controllers OU.

These are some of the most common use cases for this cmdlet of the day. For a full breakdown, check out the Microsoft documentation.

3 comments

  • Ok I got it. I’ve always felt uncomfortable with the -filter with Get-AD commands. Saying it’s WQL helps to remember. But I don’t know if there is a difference between :

    Get-ADComputer -filter “Name ‘like ‘*WEB*'”
    and
    Get-ADComputer -filter {(Name -like ‘*WEB*’)}

    Is there a difference then or is it just another way of writing ?

  • What is the available language for the filter parameter? WQL?

Leave a Reply