Techmentor: DSQuery and DSMod examples

During the command line scripting session, I demonstrated how to use the directory service command line tools like dsmod, dsquery and dsget. You can get syntax help by running ‘dsquery /?’ (or dsmod,dsadd,dsget). There’s a lot of help information so you’ll probably want to pipe the results using More (dsquery /? | more) You can also get help on each subcommand by using ‘dsmod user /?’

Here’s my list of demos. You can change the distinguished name of the starting path to match a container or domain root in your network. The character after -limit is a zero.

display all users in the domain by DN:
dsquery user -limit 0

display all users in the sales ou by samid
dsquery user ou=sales,dc=matrix,dc=local -limit 0 -o samid

query all users in the sales ou by dn and get their display name and dept
dsquery user ou=sales,dc=matrix,dc=local -limit 0 -o dn|dsget user -display -dept

query all users in the sales ou by dn and set their department
dsquery user ou=sales,dc=matrix,dc=local -limit 0 -o dn|dsmod user -dept “Sales”

Technorati Tags:


One thought on “Techmentor: DSQuery and DSMod examples

  1. I just stumbled on dsquery and dsmod. I was using them as separate commands, outputting dsquery results into a text file, then creating a new batch file using the results for a dsmod script. I knew there was a way to pipe the results, I just didn’t know how …

    thanks for the info on dsquery … | dsmod …

Comments are closed.