powershelldnswindows-server-2008domaincontroller

DSGET outputs only few results


We have about 500 Users and we need to get a complete list of them, including service and administrator accounts.

DSQUERY from the following example will return all users but DSGET returns only about 10 results.

dsquery user -limit 0 | dsget user

Any ideas why this is happening and how to get all the output from DSQUERY to be processed through DSGET?


Solution

  • I've never used dsquery but getting a list of all user accounts in AD is very easy with powershell. Just change the properties list to suit your requirements:

    Get-ADUser -Filter * -Properties SamAccountName,HomeDrive,HomeDirectory,DistinguishedName
    

    You can save the output to csv also:

    Get-ADUser -Filter * -Properties SamAccountName,HomeDrive,HomeDirectory,DistinguishedName | Export-Csv "C:\folder\adusers.csv" -NoTypeInformation
    

    EDIT: To only export specific properties you just need to select them before exporting to CSV:

    Get-ADUser -Filter * -Properties SamAccountName,HomeDrive,HomeDirectory,DistinguishedName | Select SamAccountName,HomeDrive,HomeDirectory,DistinguishedName | Export-Csv "C:\folder\adusers.csv" -NoTypeInformation
    

    ...or a slightly neater way:

    $Properties = "SamAccountName,HomeDrive,HomeDirectory,DistinguishedName"
    Get-ADUser -Filter * -Properties $Properties | Select $Properties | Export-Csv "C:\folder\adusers.csv" -NoTypeInformation