Get-ADComputer -Filter Example

Get-ADComputer with Filter parameter

The PowerShell command Get-ADComputer is part of the Active Directory PowerShell module. Go to this article if you want to know how to install it.

To search effectively for computers in your Active Directory you should use the Filter switch. Don’t extract all computers and then search the result set.

Use Get-ADComputer -Filter to search directly for improved performance.

Understand the Get-ADComputer Filter Parameter

With the many various filtering options available (LDAP filtering, oData v3.0 filtering, etc.) the filter switch often causes some confusion.

The filter switch used in the Get-ADComputer command uses the PowerShell expression language in the query string.

This is different than e.g. when using the Get-AzureADUser command (which uses oData v3.0 filtering)!

The following operators should cover most of your needs:

OperatorMeaningSample expression
-eqEqual toName -eq “WKS-2021”
-neNot equal toOperatingSystemVersion -ne “10.0 (14393)”
-gtGreater thanLastLogonTimestamp -gt $date
-geGreater than or equalCreated -ge “01-01-2018”
-ltLess thanModified -lt “01-02-2021”
-leLess than or equalCreated -le “01-01-2018”
-likeWildcard searchOperatingSystem -like “*2008*”
-notlikeWildcard search with negationOperatingSystem -notlike “*2016*”
-andAndOperatingSystem -like “*Server*” -and operatingSystemServicePack -eq “Service Pack 1”
-orOrOperatingSystem -like “*2008*” -or OperatingSystem -like “*2016*”

Please notice the following in the above examples:

  • Enclose the compared value(s) in apostrophes
  • Use -like ‘*’ and -notlike ‘*’ to find empty or non-empty values 
  • Filter “cryptic” date/time formats directly with a DateTime variable (like e.g. the LastLogonTimeStamp attribute which uses the FileTime format)

Below you have some code snippets that should point you in the right direction on how to structure your filters for your Get-ADComputer search queries:

Get-ADComputer -Filter 'Name -eq "WKS-2021"'
Get-ADComputer -Filter 'OperatingSystemVersion -ne "10.0 (14393)"'
$Date = (Get-Date).AddDays(-60)
Get-ADComputer -Filter 'lastLogonTimestamp -gt $date'
Get-ADComputer -Filter 'Modified -ge "06-04-2021 12:00:00"'
$Date = (Get-Date).AddDays(-60)
Get-ADComputer -Filter 'lastLogonTimestamp -lt $date'
Get-ADComputer -Filter 'Created -le "01-01-2020"'
Get-ADComputer -Filter 'OperatingSystem -like "*2008*"'
Get-ADComputer -Filter 'OperatingSystem -notlike "*2016*"'
Get-ADComputer -Filter 'OperatingSystem -like "*Server*" -and operatingSystemServicePack -eq "Service Pack 1"'
Get-ADComputer -Filter 'OperatingSystem -like "*2008*" -or OperatingSystem -like "*2016*"'

How to Manage Office 365 from Active Directory

Easy365Manager is a snap-in to AD Users & Computers that allows you to manage Office 365 mailboxes and licenses as part of your standard AD management.

Create an Office 365 mailbox using Easy365Manager
Assigning an Office 365 license from AD user properties

Easy365Manager extends user properties with two new tabs, so you no longer have to switch between multiple web consoles to perform daily management:

easy365manager ui
User properties, "Office 365" tab
easy365manager ui
User properties, "Mailbox tab"

With Easy365Manager, you can perform all daily tasks from AD Users & Computers:

  • Assign Office 365 licenses
  • Manage shared mailbox delegation
  • Configure calendar permissions
  • Configure proxyAddresses (with format and uniqueness check)
  • Replicate Azure AD Connect

And a lot more. See the complete feature list here

Additionally, Easy365Manager lets you remove your on-premises Exchange Server. This will give you 100% protection from future zero-day exploits targeting Exchange Server.

Try the fully functional 30-day trial now. It only takes a few minutes to install, has zero learning curve, and you’re guaranteed to have saved hours of work before the end of the week!

Did you like this post? Maybe your friends will too!