Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Techmentor: DSQuery and DSMod examples

Posted on March 21, 2006August 5, 2009

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:
Commandline
Scripting
Active Directory

Share this:

  • Print (Opens in new window) Print

Like this:

Like Loading…

Related

1 thought on “Techmentor: DSQuery and DSMod examples”

  1. Tom Indigo says:
    August 23, 2007 at 3:23 pm

    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.

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2026 The Lonely Administrator | Powered by SuperbThemes!
%d