Tuesday, January 19, 2016

Powershell - Export-CSV all users in a specified OU

Today I needed this gem and had forgotten to save it last time.. so this time it's saved AND posted.


echo off
Import-Module activedirectory

$export=read-host "Please enter the export path"
$ou=read-host "Please enter the OU in ldap format (ou=employees,ou=people,dc=domain...)"
get-aduser -filter * -searchbase "$ou" -properties Displayname, Samaccountname | export-csv "$export"


No comments:

Post a Comment