How-to Guides

How to List All Computers in an Organizational Unit (OU)

There are times when you need to find all computer accounts in a specific Organizational Unit (OU). You can try using Active Directory Users and Computers, but it is time consuming and inflexible.

An alternative to this is to write a PowerShell script. When you need to retrieve a list of computer names, the Get-ADComputer cmdlet is the most useful. You can use –Filter and specify the target OU via –SearchBase to restrict the output of your query. Add the Export-Csv parameter at the end, run the script, and then open the resulting csv file to examine the results of the commands.

Using PowerShell

Open the Powershell ISE and run the following script, adjusting the OU and path for the export:

$OUpath = 'ou=Accounts,dc=TestOU,dc=dmopc'
$ExportPath = 'c:\data\computers_in_ou.csv'
Get-ADComputer -Filter * -SearchBase $OUpath | Select-object
DistinguishedName,DNSHostName,Name | Export-Csv -NoType $ExportPath

Open the file produced by the script in MS Excel:

How Lepide Auditor Helps

Lepide Auditor for Active Directory provides several pre-defined reports to make AD auditing easy and to list all computers in an OU, you can use the All Computers Report:

To run the All Computers Report:

  • Select Lepide Auditor, Reports and from this screen, expand Active Directory, select All Computers
  • Add a filter to specify the OU
  • Select Generate Report
  • The report is generated and can be filtered, sorted and exported to CSV and PDF format
Exit mobile version