PowerShell Get-AdComputer Cmdlet

Windows PowerShell Get-AdComputer -filterPowerShell Get-AdComputer

If you are new to PowerShell’s active directory family of cmdlets, then before you try AdComputer I recommend you start by mastering the basics of Get-AdUser.

Topics PowerShell Get-Computer -filter


Preparation: Checklist for Get-AdComputer

a) Logon: At a Domain Controller
b) Find: Active Directory Module for Windows PowerShell
c) Launch: The PowerShell executable
d) Run: Import-Module activedirectory
e) Prelim Test: Examine installed services and modules thus:

# PowerShell Check for Active Directory Services
Get-Service ad*

Example 1: Get-AdComputer -filter

This family of active directory cmdlets borrows syntax from PowerShell’s expression language.  What works for me is combine an LDAP property for example, Name, a comparator such as -Like, and finally a value.

# PowerShell AdUser example to find ‘Head Office’ computers
Get-Computer -filter ‘name -Like "Head Office*" ‘

These three components (LDAP property, comparator and value) make for complex syntax, and this is why we need brackets and speech marks.  Studying the job of each syntactic element is the secret of getting cmdlets such as Get-AdComputer -filter to produce the results you need.

Note 1:  Get-AdComputer supports the more parameters, for example, -searchbase or -LDAPFilter.

Example 2: Get-AdComputer -filter {Complex and with brackets}

I suggest that you compare examples 2 with example 1.  I have deliberately replaced the ‘single speech marks’ with {curly} brackets.  My point is I want to emphasise that this syntax supports alternatives, but you have a legitimate method for PowerShell to parse the script.  I also wanted to show you how to combine two conditions and thus build a query.  (The computer Name starts with "Office", and Location is in London)

# PowerShell AdUser example to find Office computers in London
Get-AdComputer -filter {(Name -Like "Office*") -And (Location -eq "London")}

Guy Recommends:  SolarWinds’ Free Bulk Import ToolFree Download Solarwinds Bulk Import Tool

Import users from a spreadsheet.  Just provide a list of the users with their fields in the top row, and save as .csv file.  Then launch this FREE utility and match your fields with AD’s attributes, click and import the users.

Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.

If you need more comprehensive application analysis software,
Download a free trial of SAM (Server & Application Monitor)

Example 3: Get-AdUser -LDAPfilter and -SearchBase

Finding specific clusters of computers or users benefits from adding the -SearchBase parameter, in this instance we are interested only in computers found in an organizational unit called ‘Raglan’.  Path

# Get-Aduser Cmdlet
$Way = "OU=Raglan,DC=burrium,DC=usk"
Get-AdComputer -LDAPfilter ‘(name=*)’ -searchBase {$Way}  | Ft Name, Location -a

Note 2: Observe how LDAPfilter uses the form ‘(Name=*)’ and not ‘(Name -eq "*").

Note 3: I introduced the variable $Way to remind you to change my script for your domain.

Note 4: It’s -searchBase that filters the Active Directory container, in this case an OU object called ‘Raglan’.

Note 5: Ft (Format-Table) just controls the output, you could add other properties such as EmailAddress.

Troubleshooting:  Get-AdComputer

If you cannot get any results, only a message saying: 
The term ‘Get-AdComputer’ is not recognized …..

Then make sure that you have loaded the Active Directory Module for Windows PowerShell.  Check with Get-Module.  See more about installing activedirectory modules.

Discover More About Get-AdComputer With Get-Help -full

This is how I discovered the -LDAPfilter and other parameters.

# PowerShell Active Directory Syntax
Get-Help Get-AdComputer -full

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

Researching Similar Active Directory Cmdlets

Once you have mastered Get-AdComputer, you may wish to know more about Set-AdUser or Add-AdComputer.  To obtain a comprehensive list of the AD cmdlets try this command:

Get-Command -Noun ad*

Amongst the results you should see:

Note 6: Naturally, you will also see these verbs and nouns in other combinations.

Summary of PowerShell Get-AdComputer

Understanding the parameters and their syntax is the key to mastering Get-AdComputer; in particular study the first parameter -filter.  If you are new to PowerShell’s active directory cmdlets take the time to check the basics.

If you like this page then please share it with your friends


See more PowerShell Active Directory Cmdlets

PowerShell Home  • Get-AdUser -filter  • Get-AdUser  • New-AdUser  • Get-AdComputer

Export-CSV  • Import CSV  • PowerShell Active Directory  • New-AdComputer

PowerShell Codeplex  • PowerShell Ad Cmdlets  • Free Import User CSVDE Tool

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.