Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Active Directory / Searching AD Groups, Users, and Computers using Wildcards

April 18, 2022 Active DirectoryPowerShell

Searching AD Groups, Users, and Computers using Wildcards

The task of searching for objects in Active Directory (users, groups, or computers) by name using some pattern, regular expression, or wildcard is not as obvious as it really seems. The matter is that by default the standard ADUC (Active Directory  Users and Computers) snap-in doesn’t allow to use wildcards in the beginning or in the middle of a search phrase.

For example, you want to search in Active Directory for all groups that contain the keyword “SQL” in their name. If you open the AD search console (Find User, Contacts, and Groups) in ADUC and perform a basic search for the SQL keyword, you will most likely not be happy with the results. ADUC will display only groups and users with the specified keyword at the beginning of their name. The rest of the objects with the keyword sql will not be found. Searching on the *sql* pattern will also give no results (wildcards just don’t work).

search active directory from ADUC console

You can quickly open the Active Directory search form using the command:

%SystemRoot%\SYSTEM32\rundll32.exe dsquery,OpenQueryWindow

Contents:
  • How to Find Active Directory Users or Groups with ADUC?
  • Searching Computers in Active Directory
  • How to Find Active Directory Groups, Users, or Computers using PowerShell?

How to Find Active Directory Users or Groups with ADUC?

You can find the objects you need in the graphical ADUC console (dsa.msc) using simple LDAP queries.

  1. To do it, open the Find menu, and select Custom Search in the dropdown list;
  2. Go to the Advanced tab;
  3. Type name=*sql* in the Enter LDAP query field.
Note. This LDAP query defines that you want to find all AD objects that contain sql keyword in their name. To do this, use the wildcard character * on both sides.

If you only want to search for AD group objects, use the following LDAP query.

(&(objectcategory=group)(name=*sql*))

search Active Directory object using wildcard LDAP filter

As you can see, all types of AD objects (groups, computers, users, gMSA service accounts) were found using this LDAP query.

You can use advanced filters in the AD Search console. To do this, enable the Filter option in the View menu and use advanced filters to refine your search.

advanced filtering in active directory search results

If you are using the Active Directory Administrative Center (dsac.exe) console for search AD objects, you can also use LDAP queries for searches. Select Global Search and switch to Convert to LDAP mode. Enter your query in the LDAP query field.

global search in Active Directory Administrative Center

Tip. In some cases, it is convenient to use saved LDAP queries in the Active Directory console to find objects.

Searching Computers in Active Directory

To search for computers and servers in Active Directory by an exact match, select Computers in the Find field and specify the name of the computer to search for.

active directory computer searching

If you need to find computers in AD using a wildcard, you need to use such an LDAP query in the Custom Search -> Advanced section of ADUC.

(&(objectcategory=computer)(name=*sql*))

How to Find Active Directory Groups, Users, or Computers using PowerShell?

You can also use the ActiveDirectory PowerShell module to find objects in AD. You can use the appropriate cmdlet to search Active Directory for a specific type of object.

  • Get-ADGroup – group search
  • Get-ADUser – user search
  • Get-ADComputer – searching for computers

First, you need to import the PowerShell module first:

Import-Module ActiveDirectory

To search for groups in AD using a wildcard, you can use the following PowerShell command:

Get-ADGroup -Filter {name -like "*sql*"} -Properties Description,info | Select Name,samaccountname,Description,info | Sort Name

powershell search ad groups wildcard

Similarly, you can search by computer name or username:

Get-ADUser -Filter {name -like "*sql*"}
Get-ADComputer -Filter {name -like "*sql*"}

If you want to perform a global search across all types of AD objects, use the Get-ADObject cmdlet:

Get-ADObject -Filter {name -like "*sql*"} –Properties * | select sAMAccountName, ObjectClass, userPrincipalName, DisplayName, Description | FT

As you can see, the command returned all object classes in AD: computer, user, group, msDS-GroupManagedServiceAccount.

Get-ADObject search in active directory objects

You can use the LDAP filter directly in the Get-ADObject command (I also added a search scope using the SearchBase option):

Get-ADObject -LdapFilter "(&(objectCategory=person)(objectClass=user)(cn=*sql*))" -SearchBase "OU=DE,DC=woshub,DC=com"

You can use the dedicated Search-ADAccount cmdlet to find disabled, inactive users or computers.

If you need to find all AD Group Managed Service Accounts (MSA and gMSA), use the command:

Get-ADServiceAccount -Filter {name -like "*sql*"}

I hope these easy ways will make it easier for you to find objects in Active Directory.

0 comment
7
Facebook Twitter Google + Pinterest
previous post
Configuring NFS Server and Client on Linux CentOS/RHEL
next post
Checking Hard Drive Health (SMART) in Windows

Related Reading

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

How to Query and Change Teams User Presence...

October 8, 2023

Installing Language Pack in Windows 10/11 with PowerShell

September 15, 2023

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Configure Google Chrome Settings with Group Policy
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • How to Find the Source of Account Lockouts in Active Directory
  • How to Disable or Enable USB Drives in Windows using Group Policy
  • Get-ADComputer: Find Computer Properties in Active Directory with PowerShell
  • Deploy PowerShell Active Directory Module without Installing RSAT
  • Configuring Proxy Settings on Windows Using Group Policy Preferences
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top