import-module ActiveDirectory <#Set the domain to search at the Server parameter. Run powershell as a user with privilieges in that domain to pass different credentials to the command. Searchbase is the OU you want to search. By default the command will also search all subOU's. To change this behaviour, change the searchscope parameter. Possible values: Base, onelevel, subtree Ignore the filter and properties parameters #> $ADUserParams=@{ 'Server' = 'rosalind.thegalaxy.local' 'Searchbase' = 'OU=demouser,OU=People,DC=thegalaxy,DC=local' 'Searchscope'= 'Subtree' 'Filter' = '*' 'Properties' = '*' } #This is where to change if different properties are required. $SelectParams = @{ 'Property' = 'SAMAccountname', 'CN', 'title', 'mobilephone', @{name = 'businesscategory'; expression = { $_.businesscategory -join '; ' } }, 'office', 'officephone', 'state', 'streetaddress', 'city', 'employeeID', 'Employeenumber', 'enabled', 'lockedout', 'lastlogondate', 'badpwdcount', 'passwordlastset', 'created' } get-aduser @ADUserParams | select-object @SelectParams | export-csv "c:\temp\outusers.csv" -Force -NoTypeInformation get-aduser @ADUserParams | select-object @SelectParams | Export-Clixml "c:\temp\outusers.xml" -Depth 3