How to Export a Computer List from Active Directory

In this blog will see how to export a computers list from Active Directory by using Powershell script into various formats, including csv and Excel.

Open the Powershell ISE → Run the below script, adjust the path for the export:

Get-ADComputer -Filter * -Property * | Select-Object
Name,OperatingSystem,OperatingSystemVersion,ipv4Address | Export-CSV
ADcomputerslist.csv -NoTypeInformation -Encoding UTF8

Using dsquery

Go to a command prompt and type the command listed below:

dsquery computer > computers.txt

Press Enter.
You will now have a computers.txt text file containing the computer accounts in your organization.

In order to export a list of computers in OUs and Sub OUs:

DSQUERY COMPUTER "OU=expert,DC=serc,DC=col" -name * -scope subtree -limit 0 > d:\ComputersinOU.TXT
DSQUERY OU "OU=expert,DC=serc,DC=col" -name * -scope subtree -limit 0 > d:\OUexpert.TXT

DSQUERY COMPUTER – start querying AD for computer objects
“OU=expert,DC=serc,DC=col” – start search in this OU
-name * – get specified computer name, in case you are using * (asterisk) then it means, any name
-scope subtree – search also in all subOUs, not only oin specified one
-limit 0 – by default DSQUERY will return the firs 100 found objects, you can overwrite it using any other value or 0. 0 means return all of them
> d:\ComputersinOU.TXT – this says, redirect all output to text file on D-Drive instead of displaying their names on a screen