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:
[stextbox id=’grey’]Get-ADComputer -Filter * -Property * | Select-Object
Name,OperatingSystem,OperatingSystemVersion,ipv4Address | Export-CSV
ADcomputerslist.csv -NoTypeInformation -Encoding UTF8[/stextbox]
Using dsquery
Go to a command prompt and type the command listed below:
[stextbox id=’grey’]dsquery computer > computers.txt[/stextbox]
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:
[stextbox id=’grey’]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[/stextbox]
[stextbox id=’info’]
- 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
[/stextbox]