PowerShell Get-ADComputer: Complete Guide to Query AD Computers
β’ 2 min read
powershell active-directory get-adcomputer computer-management ad-cmdlets tutorial
PowerShell Get-ADComputer: Complete Guide to Query Active Directory Computers
Overview
The Get-ADComputer cmdlet allows you to search for and retrieve computer objects from Active Directory. Itβs essential for managing workstations, servers, and other devices in your domain.
Common Tasks:
- Find computers by name or IP address
- Query enabled/disabled computers
- Find computers in specific OU or location
- Get computer properties (OS, last logon, etc.)
- Export computer inventory
- Identify inactive computers
Prerequisites:
- PowerShell 5.1 or later
- Active Directory PowerShell module
- Read permissions to computer objects
Syntax
Get-ADComputer [-Identity <ADComputer>] [-Filter <string>] [-Properties <string[]>] [-SearchBase <string>]
```powershell
### Key Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `-Identity` | String | Computer to query (hostname, DN, SID) |
| `-Filter` | String | LDAP filter for searching computers |
| `-Properties` | String[] | Attributes to retrieve |
| `-SearchBase` | String | OU to search within |
| `-ResultSetSize` | Int | Maximum results to return |
---
## Examples
### Example 1: Get Specific Computer
```powershell
Get-ADComputer -Identity "workstation01"
```powershell
**Output:**
```powershell
DistinguishedName : CN=workstation01,CN=Computers,DC=contoso,DC=com
DNSHostName : workstation01.contoso.com
Enabled : True
Name : workstation01
ObjectClass : computer
ObjectGUID : a1b2c3d4-e5f6-7890-abcd-ef1234567890
SamAccountName : workstation01$
```powershell
### Example 2: Get All Enabled Computers
```powershell
Get-ADComputer -Filter "enabled -eq $true" -Properties Name, OperatingSystem
```powershell
### Example 3: Find Computers by Operating System
```powershell
Get-ADComputer -Filter "operatingSystem -like '*Windows 11*'" -Properties OperatingSystem |
Select-Object Name, OperatingSystem
```powershell
### Example 4: Find Disabled Computers
```powershell
Get-ADComputer -Filter "enabled -eq $false" | Select-Object Name, DistinguishedName
```powershell
### Example 5: Get Computers in Specific OU
```powershell
$ouPath = "OU=Workstations,OU=Computers,DC=contoso,DC=com"
Get-ADComputer -Filter "enabled -eq $true" -SearchBase $ouPath
```powershell
### Example 6: Find Computers by DNS Name Pattern
```powershell
Get-ADComputer -Filter "dNSHostName -like '*workstation*'" -Properties DNSHostName
```powershell
### Example 7: Get Computer Details with Multiple Properties
```powershell
Get-ADComputer -Identity "server01" -Properties OperatingSystem, LastLogonDate, Description
```powershell
### Example 8: Export All Computers to CSV
```powershell
Get-ADComputer -Filter * -Properties OperatingSystem, DNSHostName, LastLogonDate |
Export-Csv -Path "C:\computers.csv" -NoTypeInformation
```powershell
---
## Common Use Cases
### Find Inactive Computers
```powershell
$date = (Get-Date).AddDays(-90)
Get-ADComputer -Filter "lastLogonDate -lt '$date'" -Properties LastLogonDate
```powershell
### Inventory Windows Servers
```powershell
Get-ADComputer -Filter "operatingSystem -like '*Server*'" -Properties OperatingSystem |
Group-Object -Property OperatingSystem | Select-Object Name, Count
```powershell
### Find Computers Needing Patches
```powershell
Get-ADComputer -Filter "operatingSystem -like '*Windows 10*'" -Properties OperatingSystem
```powershell
---
## Best Practices
β
**Specify properties needed** - Don't use `-Properties *` unless necessary
β
**Use SearchBase** - Limits scope for faster queries on large domains
β
**Filter efficiently** - Use -Filter instead of Where-Object when possible
### Related Commands
- **[Get-ADUser](/powershell-get-aduser)** - Query users
- **[Get-ADGroup](/powershell-get-adgroup)** - Query groups
---
## FAQs
**Q: How do I find computers that haven't logged in?**
A: Use lastLogonDate filter with date comparison.
**Q: Can I search by IP address?**
A: Not directly with Get-ADComputer. You need to use DNS resolution or additional tools.
**Q: How do I get all properties for a computer?**
A: Use `-Properties *` but be aware this is slower.
---
## See Also
- **[PowerShell Get-ADUser](/powershell-get-aduser)** - Query users
- **[Active Directory Computer Management](/active-directory-computer-management)** - Computer guide
- **[PowerShell Bulk AD Operations](/powershell-bulk-ad-operations)** - Bulk management
- **Complete Active Directory Guide** - AD fundamentals
---
**Last Updated:** February 6, 2026
**Difficulty Level:** Intermediate
**Reading Time:** 10 minutes