Add commas to dsquery output

7.5k views Asked by At

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?

1

There are 1 answers

0
user1681573 On

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.