Skip to content

Instantly share code, notes, and snippets.

@alexinnes
Created June 9, 2015 08:48
Show Gist options
  • Save alexinnes/942175f54a44bd8f4526 to your computer and use it in GitHub Desktop.
Save alexinnes/942175f54a44bd8f4526 to your computer and use it in GitHub Desktop.
Get Computers in Active Directory in Certain OUs
#Where do you want the file to be exported to
$Export = "C:\"
#What OU Do you want to target
$OU=@("OU=PS,DC=ps,DC=internal","OU=TCASP,DC=ps,DC=internal")
#loop through the array of OUs and find all the computers. Selects the: Name, Operatingsystem, lastlogondate, modified, Created and Canonicalname and exports to CSV
$OU | foreach { get-adcomputer -Filter * -SearchBase $_ -Properties *
| select -Property Name, Operatingsystem, lastlogondate, modified, Created, Canonicalname} | export-csv $Export
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment