Disclaimer
This is my personal blog. The opinions and views I express are my own. The information I provide is on an as-is basis. I make no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this blog and will not be liable for any errors, omissions, or delays in this information or any losses, injuries or damages arising from its use.

Search Active Directory OU for computer Accounts, export to CSV

** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK **

This is a very simple script that will search an Active Directory OU for Computer accounts and exports the results to a CSV file. It also includes in the search any child OUs.

I’m pretty sure it requires Powershell V3 and it will require importing the AD Module.

$ou = "OU=Computers,DC=test,DC=com"
$logpath = "C:\scripts\computer.csv"

Get-ADcomputer -Filter * -Searchbase $ou -Property cn,name | Export-csv $logpath -append
Write-host -foregroundcolor cyan "Script complete" 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.