{"id":25,"date":"2006-03-21T08:38:00","date_gmt":"2006-03-21T12:38:00","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/2006\/03\/21\/techmentor-dsquery-and-dsmod-examples\/"},"modified":"2009-08-05T13:03:50","modified_gmt":"2009-08-05T17:03:50","slug":"techmentor-dsquery-and-dsmod-examples","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/","title":{"rendered":"Techmentor: DSQuery and DSMod examples"},"content":{"rendered":"<p>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 \/?'<\/p>\n<p>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.<\/p>\n<p>display all users in the domain by DN:<br \/>dsquery user -limit 0<\/p>\n<p>display all users in the sales ou by samid<br \/>dsquery user ou=sales,dc=matrix,dc=local -limit 0 -o samid<\/p>\n<p>query all users in the sales ou by dn and get their display name and dept<br \/>dsquery user ou=sales,dc=matrix,dc=local -limit 0 -o dn|dsget user -display -dept<\/p>\n<p>query all users in the sales ou by dn and set their department<br \/>dsquery user ou=sales,dc=matrix,dc=local -limit 0 -o dn|dsmod user -dept \"Sales\"<\/p>\n<p><font face=\"tahoma\" size=1>Technorati Tags:<br \/><a href=\"http:\/\/www.technorati.com\/tags\/commandline\" rel=\"tag\">Commandline<\/a><br \/><a href=\"http:\/\/www.technoratic.com\/tags\/scripting\" rel=\"tag\">Scripting<\/a><br \/><a href=\"http:\/\/www.technoratic.com\/tags\/Active Directory\" rel=\"tag\">Active Directory<\/a><\/p>\n<p><\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8216;dsquery \/?&#8217; (or dsmod,dsadd,dsget). There&#8217;s a lot of help information so you&#8217;ll probably want to pipe the results using More (dsquery \/? | more) You can&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8,9],"tags":[539,20],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-scripting","category-training","tag-active-directory","tag-cli"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Techmentor: DSQuery and DSMod examples &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Techmentor: DSQuery and DSMod examples &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"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 &#039;dsquery \/?&#039; (or dsmod,dsadd,dsget). There&#039;s a lot of help information so you&#039;ll probably want to pipe the results using More (dsquery \/? | more) You can...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2006-03-21T12:38:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2009-08-05T17:03:50+00:00\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/25\\\/techmentor-dsquery-and-dsmod-examples\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/25\\\/techmentor-dsquery-and-dsmod-examples\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Techmentor: DSQuery and DSMod examples\",\"datePublished\":\"2006-03-21T12:38:00+00:00\",\"dateModified\":\"2009-08-05T17:03:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/25\\\/techmentor-dsquery-and-dsmod-examples\\\/\"},\"wordCount\":197,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"keywords\":[\"Active Directory\",\"CLI\"],\"articleSection\":[\"Scripting\",\"Training\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/25\\\/techmentor-dsquery-and-dsmod-examples\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/25\\\/techmentor-dsquery-and-dsmod-examples\\\/\",\"name\":\"Techmentor: DSQuery and DSMod examples &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2006-03-21T12:38:00+00:00\",\"dateModified\":\"2009-08-05T17:03:50+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/25\\\/techmentor-dsquery-and-dsmod-examples\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/25\\\/techmentor-dsquery-and-dsmod-examples\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/25\\\/techmentor-dsquery-and-dsmod-examples\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Scripting\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/scripting\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Techmentor: DSQuery and DSMod examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Techmentor: DSQuery and DSMod examples &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/","og_locale":"en_US","og_type":"article","og_title":"Techmentor: DSQuery and DSMod examples &#8226; The Lonely Administrator","og_description":"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...","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/","og_site_name":"The Lonely Administrator","article_published_time":"2006-03-21T12:38:00+00:00","article_modified_time":"2009-08-05T17:03:50+00:00","author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Techmentor: DSQuery and DSMod examples","datePublished":"2006-03-21T12:38:00+00:00","dateModified":"2009-08-05T17:03:50+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/"},"wordCount":197,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"keywords":["Active Directory","CLI"],"articleSection":["Scripting","Training"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/","name":"Techmentor: DSQuery and DSMod examples &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"datePublished":"2006-03-21T12:38:00+00:00","dateModified":"2009-08-05T17:03:50+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Scripting","item":"https:\/\/jdhitsolutions.com\/blog\/category\/scripting\/"},{"@type":"ListItem","position":2,"name":"Techmentor: DSQuery and DSMod examples"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":64,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/64\/more-one-liners\/","url_meta":{"origin":25,"position":0},"title":"More One Liners","author":"Jeffery Hicks","date":"November 13, 2006","format":false,"excerpt":"I recently did a TipSheet column listing some of my favorite quick, one line commands. Reader Wayne was kind enough to share with me his list of oft-used one-liners which he graciously offered to share. I have not tested many of these personally, but you always test things in a\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":140,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/140\/more-cli-one-liners\/","url_meta":{"origin":25,"position":1},"title":"More CLI One-Liners","author":"Jeffery Hicks","date":"May 6, 2008","format":false,"excerpt":"In the past I've posted a collection of command one-liners that get a ton of work done with (relatively) minimal effort. Many of these have come from Wayne Martin. I've been behind in my blogging while book writing, but I wanted to make sure you checked out his latest list\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":135,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/135\/waynes-world-of-it\/","url_meta":{"origin":25,"position":2},"title":"Wayne&#8217;s World of IT","author":"Jeffery Hicks","date":"March 7, 2008","format":false,"excerpt":"One of my more popular blog entries is the one I did about CMD one-liners. These are little tidbits of commands that can get a lot done. The list came from a reader and I was happy to share. Wayne has now started a blog Wayne's World of IT which\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":149,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/149\/waynes-world-of-tips\/","url_meta":{"origin":25,"position":3},"title":"Waynes World of Tips","author":"Jeffery Hicks","date":"September 22, 2008","format":false,"excerpt":"I've blogged in the past about Wayne Martin and his outstanding list of command line tips. These are one line commands, some complex some simple, that you can use to accomplish a wide range of task. The overall number of tips is to 425 and Wayne recently reorganized them into\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7817,"url":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/","url_meta":{"origin":25,"position":4},"title":"Distinguished Parsing with PowerShell and Regex","author":"Jeffery Hicks","date":"October 29, 2020","format":false,"excerpt":"The other day I'm chatting with my friend Gladys Kravitz about Active Directory and she makes an off-hand remark about parsing out organizational unit names from a distinguished name. On one hand, this is a pretty simple task, assuming a proper distinguished name from the Active Directory cmdlets. All you\u2026","rel":"","context":"In &quot;Active Directory&quot;","block_context":{"text":"Active Directory","link":"https:\/\/jdhitsolutions.com\/blog\/category\/active-directory\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ignore-case.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ignore-case.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ignore-case.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ignore-case.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":2476,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2476\/counting-users-by-ou-with-powershell\/","url_meta":{"origin":25,"position":5},"title":"Counting Users by OU with PowerShell","author":"Jeffery Hicks","date":"August 3, 2012","format":false,"excerpt":"I've been following a discussion thread in the PowerShell forum at ScriptingAnswers.com. The post is about counting the number of users in an OU. Well that sounds like fun. We got him started using the Quest AD cmdlets. I thought I'd share some of the code I posted. The test\u2026","rel":"","context":"In &quot;Active Directory&quot;","block_context":{"text":"Active Directory","link":"https:\/\/jdhitsolutions.com\/blog\/category\/active-directory\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}