Query and Export Active Directory Computers with PowerShell
Active Directory computer objects provide a useful inventory of domain-joined devices, but the directory record is not always a live view of the endpoint. PowerShell can query those objects efficiently and turn them into structured data for operational reviews.
The practical workflow combines the Active Directory module, targeted filters, selected properties and a predictable export format. This avoids scanning the entire directory when you only need particular operating systems, offices or device groups.
A dependable export should be more than a list of hostnames. It should preserve DNS details, IP addresses, operating system information and timestamps that help determine whether a computer account remains active.
Australian administrators often manage a mixture of on-premises Active Directory, Microsoft 365, Microsoft Entra ID and cloud-hosted workloads. Local PowerShell automation can bridge these environments by producing a consistent inventory across traditional data centres, regional offices and hybrid infrastructure.
Querying computer objects with the Active Directory module
On a domain-joined Windows system, install the Active Directory PowerShell module through Remote Server Administration Tools, then confirm that the current account can read the relevant domain objects. The Get-ADComputer cmdlet can then return computer accounts with the required properties.
Import-Module ActiveDirectory
Get-ADComputer -Properties Name,DNSHostName,OperatingSystem,OperatingSystemVersion,IPv4Address,IPv6Address,LastLogonDate
This command returns directory records rather than discovering devices on the network. The DNS host name may differ from the account name, while LastLogonDate provides an approximate indication of recent activity. In a large domain, narrowing the query before collecting detailed properties reduces unnecessary load.
Filtering for the computers you need
Filtering occurs on the domain controller and reduces the amount of data returned to the workstation. The cmdlet accepts LDAP-style expressions through its Filter parameter, making operating system and naming conventions useful starting points.
Get-ADComputer -Filter {OperatingSystem -like '*Windows 11*'} `
-Properties Name,DNSHostName,LastLogonDate
A comparison against LastLogonDate is usually handled in PowerShell after retrieving the selected values. This example finds computer accounts that have not recorded activity for 90 days.
$cutoff = (Get-Date).AddDays(-90)
Get-ADComputer -Properties Name,DNSHostName,LastLogonDate |
Where-Object { $_.LastLogonDate -and $_.LastLogonDate -lt $cutoff }
LastLogonDate is derived from replicated directory data and should be treated as an estimate rather than an exact endpoint login timestamp. Null values can also occur on older or inactive accounts. For individual investigations, the Identity parameter retrieves a known computer account directly, while SearchBase can restrict a query to a particular organisational unit.
Building a practical computer inventory
Start with a deliberate property set and use Select-Object to shape the output. Joining address collections into semicolon-separated values also makes the result easier to consume in Excel and other reporting tools.
$inventory = Get-ADComputer -Properties Name,DNSHostName,OperatingSystem,OperatingSystemVersion,IPv4Address,IPv6Address,LastLogonDate,PasswordLastSet |
Select-Object Name, DNSHostName, OperatingSystem, OperatingSystemVersion, `
@{Name='IPv4';Expression={$_.IPv4Address -join ';'}}, `
@{Name='IPv6';Expression={$_.IPv6Address -join ';'}}, `
LastLogonDate, PasswordLastSet
The PasswordLastSet value belongs to the computer account and has no connection to a human user's password. Similarly, OperatingSystemVersion reflects the operating system recorded in Active Directory, which may lag behind a recently upgraded endpoint. Keeping Name and DNSHostName together makes it easier to reconcile the directory export with endpoint-management tools and DHCP records.
Exporting and validating computer inventories
CSV remains the most portable choice for operational spreadsheets and straightforward review. The Export-Csv cmdlet converts the selected objects into rows while preserving property names as column headings.
$inventory |
Export-Csv -Path .\computer-inventory.csv -NoTypeInformation -Encoding UTF8
Useful fields for most inventories
NameandDNSHostNamefor matching directory accounts to network endpointsOperatingSystemandOperatingSystemVersionfor platform and upgrade reviewsIPv4andIPv6for address reconciliation and network planningLastLogonDateandPasswordLastSetfor activity and machine-account checks
JSON suits APIs and automation that need structured documents, while Export-Clixml preserves PowerShell object types and date values for later use with Import-Clixml. These formats can support a repeatable inventory pipeline rather than relying on manual spreadsheet work.
Checks before sharing an export
- Compare the exported row count with the number of records returned by the source query
- Re-query a known device by
Identityto confirm that its details are accurate - Record the generation time, domain controller and filter in a filename or manifest
- Restrict write access and apply an appropriate retention period to the resulting file
For recurring reporting, wrap the query and export in a PowerShell script and store the output in a protected share. Logging failures for individual scopes prevents a regional connectivity problem from going unnoticed.
Running safely across Australian IT environments
Read-only queries should run against the domain controller holding the relevant records. Get-ADDomain identifies the current domain, and the Server parameter allows a particular domain controller to be selected when replication or site routing makes that necessary.
Get-ADComputer -Server 'dc-syd-01.au.example.com' `
-Filter {OperatingSystem -like '*Windows 11*'}
Australian organisations commonly connect staff across Sydney, Melbourne, Brisbane, Perth and regional branches. A full-domain query may cross a wide area network, so scheduled runs, sensible organisational-unit scopes and captured errors help maintain reliable operations.
Record timestamps in UTC while documenting the source timezone. Sydney and Melbourne observe AEST and AEDT, Adelaide uses ACST and ACDT, and Perth remains on AWST without daylight saving. Australian business documents also commonly use DD/MM/yyyy, making ISO 8601 timestamps valuable when files move between local and overseas teams.
Many Australian IT functions combine internal administrators with managed service providers, while identity services span on-premises Active Directory, Entra ID and Microsoft 365. Keep exports limited to operational requirements and apply Australian Privacy Act controls when computer records can be linked to identifiable users. For an arvo handover, a timestamped CSV and a CLIXML archive provide both readability and type fidelity. Administrators can compare this workflow with the broader IT Diversified guides covering PowerShell, Windows administration, VMware, AWS and infrastructure automation. A validated export tied to a specific domain controller, filter and timestamp becomes dependable evidence during patching, audits and operational handovers.