Active Directory can be queried from command line using PowerShell or legacy dsquery commands.

PowerShell Active Directory Commands

List all users:

Command
Get-ADUser -Filter *

Find specific user:

Command
Get-ADUser -Identity "username"

Search user by name:

Command
Get-ADUser -Filter "Name -like '*John*'"

List all computers:

Command
Get-ADComputer -Filter *

List all groups:

Command
Get-ADGroup -Filter *

Get domain info:

Command
Get-ADDomain

Get domain controllers:

Command
Get-ADDomainController -Filter *

Enable PowerShell AD Module

If Get-ADUser doesn't work, enable the module:

Windows Server:

Command
Import-Module ActiveDirectory

Windows 10/11: Install RSAT (Remote Server Administration Tools) from Settings > Apps > Optional Features.

Then run:

Command
Import-Module ActiveDirectory

Legacy DSQUERY Commands

Works without PowerShell module on domain-joined machines.

Find all users:

Command
dsquery user

Find user by name:

Command
dsquery user -name "John*"

Find all computers:

Command
dsquery computer

Find all groups:

Command
dsquery group

Find disabled accounts:

Command
dsquery user -disabled

Find inactive computers (90 days):

Command
dsquery computer -inactive 12

12 weeks = 90 days approximately.

Get Detailed User Info

PowerShell - show all properties:

Command
Get-ADUser -Identity "username" -Properties *

DSGET (legacy):

Command
dsquery user -name "username" | dsget user -display -email -mobile

Find User's Group Memberships

PowerShell:

Command
Get-ADPrincipalGroupMembership -Identity "username"

DSGET:

Command
dsget user "CN=Username,OU=Users,DC=domain,DC=com" -memberof

Find Members of a Group

PowerShell:

Command
Get-ADGroupMember -Identity "GroupName"

DSGET:

Command
dsget group "CN=GroupName,OU=Groups,DC=domain,DC=com" -members

Check if User is Locked Out

PowerShell:

Command
Get-ADUser -Identity "username" -Properties LockedOut | Select-Object Name,LockedOut

Unlock user:

Command
Unlock-ADAccount -Identity "username"

Reset User Password

Command
Set-ADAccountPassword -Identity "username" -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "NewPassword123!" -Force)

Force password change at next logon:

Command
Set-ADUser -Identity "username" -ChangePasswordAtLogon $true

Search for Computer

By name:

Command
Get-ADComputer -Filter "Name -like '*DESKTOP*'"

By operating system:

Command
Get-ADComputer -Filter "OperatingSystem -like '*Windows 11*'" -Properties OperatingSystem

Export Results to CSV

PowerShell:

Command
Get-ADUser -Filter * -Properties DisplayName,EmailAddress | Export-Csv users.csv -NoTypeInformation

Creates CSV file with user data.

Common Filters

Users created in last 30 days:

Command
$date = (Get-Date).AddDays(-30)
Get-ADUser -Filter "Created -gt '$date'" -Properties Created

Users never logged in:

Command
Get-ADUser -Filter "LastLogonDate -notlike '*'" -Properties LastLogonDate

Computers not logged in for 90 days:

Command
$date = (Get-Date).AddDays(-90)
Get-ADComputer -Filter "LastLogonDate -lt '$date'" -Properties LastLogonDate

Troubleshooting

"Get-ADUser not recognized": Import ActiveDirectory module or install RSAT.

"Unable to contact server": Not on domain network or domain controller unreachable.

"Access denied": Need domain admin or appropriate AD permissions.

DSQUERY returns nothing: Check syntax, ensure domain-joined, verify network connection.

Bottom Line

PowerShell (modern):

Command
Get-ADUser -Filter * | Find users
Get-ADComputer -Filter * | Find computers
Get-ADGroup -Filter * | Find groups

DSQUERY (legacy):

Command
dsquery user | Find users
dsquery computer | Find computers
dsquery group | Find groups

PowerShell is more powerful but requires ActiveDirectory module. DSQUERY works on domain-joined machines without additional setup.

Both require domain network connection and appropriate permissions.