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 /?'

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

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


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

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.

reports

Powered by Buttondown.

Join me on Mastodon

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

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