** 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"