• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 938
  • Last Modified:

Need help querying specific attributes using DSQUERY and exporting to CSV

You would think this is simple, but I can't find my answers anywhere.  I have a spreadsheet with a users display name, employee number, and their user ID for a program we use here at work.  Any time I'm using dsquery to get the required information it is leaving a ton of blank spaces in the CSV, and it's not pulling the "employeeID" attribute I'm trying to get it to pull - just the cn.  That, and when I can manipulate things to make it pull multiple attribute values at once, it is putting all of the information for a single user (also grabbing computers) in a single cell in the CSV which is completely useless to me.  Can somebody help?
0
Archie314
Asked:
Archie314
  • 3
1 Solution
 
Michael PfisterCommented:
dsquery * dc=domain_part1,dc=domain_part2 -filter "(&(objectCategory=Person)(objectClass=User))" -attr samaccountname employeeID displayname

To import it into Excel, use "Import Text file" and select fixed column width.

HTH
0
 
Michael PfisterCommented:
To generate a real CSV file, you can run the following script (modify the domain info matching your domain)
if exist userlist.csv del userlist.csv
dsquery * dc=domain_part1,dc=domain_part2 -filter "(&(objectCategory=Person)(objectClass=User))" -attr samaccountname employeeID displayname>templist.tmp
for /f "tokens=1-4" %%a in (templist.tmp) do echo "%%a";"%%b";"%%c %%d">>userlist.csv

Open in new window

0
 
Archie314Author Commented:
Thank you for the assistance.
0
 
Michael PfisterCommented:
Hi, Archie314, why only "B" grade? Whats missing from my solution?
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now