HOWTO · PowerShell

How to Get-ADComputer -Filter in PowerShell

Learn how to use Get-ADComputer -Filter in PowerShell to find Active Directory computer accounts by name or operating system, select properties, and export the results.

On this page

Use Get-ADComputer -Filter to find Active Directory computer accounts by their attributes. The -Filter parameter takes a PowerShell-style expression such as Name -like '*elitebook*' that the domain controller evaluates server side, and the cmdlet returns one computer object per matching account. The Active Directory commands below require the ActiveDirectory module, which installs with the Remote Server Administration Tools (RSAT) or is already present on a domain controller, plus a reachable domain. They are written as adaptable inline syntax because they only run inside that environment; the fenced programs are self-contained runnable equivalents of those comparisons, and each one’s observed output is shown directly below it.

Retrieve a computer account with Get-ADComputer

Get-ADComputer retrieves one or more computer accounts from Active Directory and ships as part of the ActiveDirectory module. On a machine where the module is installed, Get-Help Get-ADComputer lists the cmdlet’s parameters and the values each one accepts.

Pass a known account to -Identity to retrieve exactly that computer: Get-ADComputer -Identity PC-01. The parameter accepts a distinguished name, a GUID, a security identifier (SID), or a sAMAccountName, so you can reference the account in whichever form your data already provides.

The result is a computer object carrying a limited default property set such as Name, DNSHostName, Enabled, and SID. Attributes like OperatingSystem are not loaded unless you ask for them; Get-ADComputer -Identity PC-01 -Properties * fetches every attribute stored on the account.

Filter computers by name

When you know only part of a computer name, -Filter locates every matching account. Inside the filter string, -like performs wildcard matching where * stands for any run of characters and the comparison ignores letter case.

Run this example:

import fnmatch

print(fnmatch.fnmatchcase('ELITEBOOK-840-G8'.lower(), '*elitebook*'))
True

The same pattern inside -Filter is applied to the Name attribute of every computer account in the directory, so Get-ADComputer -Filter "Name -like '*elitebook*'" returns all matching machines. The match runs on the domain controller before results cross the network, which is much faster than retrieving every account and testing it locally with Where-Object. Each match arrives as a computer object, so you can pipe the result to Format-Table, Select-Object, or any other cmdlet for further processing.

Filter computers by operating system and multiple criteria

Administrators often need a list of machines running a given operating system, for example to plan upgrades or target a policy. The OperatingSystem attribute stores a string such as Windows 10 Enterprise, so Get-ADComputer -Filter "OperatingSystem -like '*Windows 10*'" matches every edition containing the version name.

-eq compares the whole attribute value, which suits exact strings, while -or and -and combine several criteria in one filter. The same comparison in runnable form:

os_name = 'Windows 11 Pro'
print(os_name == 'Windows 10' or os_name == 'Windows 11 Pro')
True

Applied to the directory, Get-ADComputer -Filter "OperatingSystem -eq 'Windows 10' -or OperatingSystem -eq 'Windows 11'" returns computers whose recorded value is exactly one of the two strings, and switching -or for -and narrows the result set instead of widening it. Recorded values usually include an edition suffix such as Pro, so a trailing wildcard like OperatingSystem -like 'Windows 10*' often matches more machines than -eq with a bare version name.

Select properties and export results

Because filtering runs on the domain controller, an attribute used inside -Filter does not have to be among the returned properties. To display or save OperatingSystem, however, request it with -Properties and shape the output with Select-Object: Get-ADComputer -Filter "OperatingSystem -like 'Windows 10*'" -Properties OperatingSystem | Select-Object Name, OperatingSystem.

Pipe the selected objects to Export-Csv to save them to a file. -NoTypeInformation omits the .NET type header so the CSV contains only the column row and data, and -Path takes any writable location: Get-ADComputer -Filter * -Properties OperatingSystem | Select-Object Name, OperatingSystem | Export-Csv -Path .\computers.csv -NoTypeInformation.

The resulting CSV opens in a spreadsheet or feeds into other PowerShell commands for reporting and follow-up administration.