Get-Aduser script only returning a small amount of results on .CSV file

Xiomara McClenton 21 Reputation points
2020-12-01T19:56:51.18+00:00

I have the following script, however when I run it it only returns random amount of results ( 254 run again 518, then 1000+ results ) but I need it to return all users which is 5000+. What can I do to fix this ?

get-aduser -filter * -Searchbase "OU=my,OU=domain,OU=Users" -properties * |
Select-Object SamAccountName,description,@{N='serialNumber';E={$_.SerialNumber[0]}} |
Export-csv C:\Users\user1\Desktop\serial.csv

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,655 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,558 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue 37,706 Reputation points Microsoft Vendor
    2020-12-02T03:57:30.717+00:00

    Hi,

    Do you have multiple domain controllers? If yes, there could be replication delays across DCs. As powershell may query different DCs, you may get differnet results if the users are recently added.

    Best Regards,
    Ian

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Andreas Baumgarten 111.4K Reputation points MVP
    2020-12-01T21:05:16.217+00:00

    Without testing:

    You didn't specified the -filter parameter with a value? If "no" I wouldn't use -filter in the query.
    The -SearchBase parameter doesn't not follow the correct syntax. It should be "OU=<Whatever>,OU=<anotherOU,DC=<domainname>,DC=<domainsuffix>"
    The parameter -properties doesn't have a value? I would use -properties * to get all properties of the user object


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.