powershellactive-directory

Extract list of users (millions) in Active Directory using Powershell


We have an Active Directory with 5 millions of users. We're getting the error "Get-ADUser : This operation returned because the timeout period expired" when trying to extract users using powershell script.

Already tried searching the web for an optimized script. Below is what we have. This works fine for ~500k users.

Import-Module ActiveDirectory

$Users = Get-ADUser -SearchBase "CN=Users,DC=*****,DC=*****,DC=*****" -Server "*****" -ResultPageSize 1 -LDAPFilter "(&(objectCategory=User)(whenCreated>=20190101000000.0Z)(whenCreated<=20190131235959.0Z))" -Properties WhenCreated | Select-Object Name, WhenCreated

$Users | Export-Csv C:\Temp\January2019.csv -NoTypeInformation

Solution

  • Thanks for all your help. Instead of using Get-ADUser, I was able to extract users using CSVDE (an LDIFDE variant that allows exporting data to CSV files) without any problem.

    CSVDE -f D:\Temp\ADUseru.csv -d "CN=Users,DC=*****,DC=*****,DC=*****" -r "(&(objectClass=user)(objectCategory=person)(whenCreated>=20120101000000.0Z)(whenCreated<=20121231235959.0Z))" -l "name, whenCreated, memberOf, sAMAccountName"