Add commas to dsquery output

user1681573 picture user1681573 · Oct 18, 2012 · Viewed 7.2k times · Source

So I'm writing a batch file that will be run by a scheduled task. This file executes a DSQuery for certain attributes of users in AD.

Here's my query:

dsquery user ou=org_unit,dc=company,dc=local -name * -limit 0 | dsget user -dn -email -tel >a.txt

So my question is how can I separate the output by commas? It shows in the text file in nice columns, but it's going to a place to be parsed out by something else for input into a database, and the parsing rules rely on commas.

I need to turn this:

CN=USER NAME,OU=ORG_UNIT,OU=ANOTHER_ORG_UNIT,DC=DOMAINROOT,DC=LOCAL (111)111-1111 [email protected]

Into this:

CN=USER NAME,OU=ORG_UNIT,OU=ANOTHER_ORG_UNIT,DC=DOMAINROOT,DC=LOCAL, (111)111-1111,  [email protected]

So how can I edit my query to make it output what I need as shown? Is there something else I can run that'll do it for me?

Answer

user1681573 picture user1681573 · Oct 18, 2012

Never mind. Figured out a CSVDE query to run it.

csvde -m -f test.txt -d "ou=org_unit,dc=domainroot,dc=local" -r objectCategory=Person -l mail,telephoneNumber

Returns what I need, in the format I need.