{"id":76,"date":"2007-02-19T12:30:00","date_gmt":"2007-02-19T20:30:00","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/02\/19\/group-membership-with-dsquerydsget\/"},"modified":"2007-02-19T12:30:00","modified_gmt":"2007-02-19T20:30:00","slug":"group-membership-with-dsquerydsget","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/02\/19\/group-membership-with-dsquerydsget\/","title":{"rendered":"Group Membership with DSQuery\/DSGet"},"content":{"rendered":"<p>Recently I was helping out in a scripting forum. The topic was getting a report of all groups and their members. I have several VBScripts to do this, but an even easier and faster way is to use the DSQuery and DSGet commands from the command line.&nbsp; Want to see all the groups in your domain or forest simply run:<\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">dsquery group<\/font><\/p>\n<p>And you&#8217;ll get a complete list of each group and its distinguished name. How easy is that? To get the members of a group all you need is<\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">dsget group GroupDN -members<\/font><\/p>\n<p>GroupDN is the distinguished name of the group. However, you save yourself the trouble of typing because you can pipe the results of the dsquery command to dsget:<\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">dsquery group<\/font> | <font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">dsget group -members<\/font><\/p>\n<p>What do you think of that? You can also use the -expand switch with dsget group if you have nested groups and want to expand the membership completely.<\/p>\n<p>Now if you ran these commands you&#8217;ll see things go by pretty quickly. If you want a simple report, you can use this batch file:<\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">@echo off<br \/>if exist membership.txt del membership.txt<br \/>dsquery group &gt;groups.txt<br \/>::The FOR command&nbsp;is one single line<br \/>for \/f &#8220;tokens=*&#8221; %%g in (groups.txt) do @echo %%g &gt;&gt;membership.txt &amp;&amp; echo Members: &gt;&gt;membership.txt &amp;&amp; dsget group %%g -members &gt;&gt;membership.txt &amp;&amp; echo **************************************** &gt;&gt;membership.txt <\/font> <\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">::display result<br \/>notepad membership.txt<\/font>  <\/p>\n<p>When you run this you will get a sort-of formatted report displayed in Notepad.  <\/p>\n<p>So the next time you&#8217;re looking for Active Directory information, don&#8217;t forget the easy to use and powerful DS commands. <\/p>\n<div style=\"margin: 0px; padding: 0px; display: inline;\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:a362a827-b270-4ed2-aa83-11e249220438\" class=\"wlWriterSmartContent\">Technorati tags: <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/Scripting\">Scripting<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/CLI\">CLI<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/ActiveDirectory\">ActiveDirectory<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/DSQuery\">DSQuery<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/DSGet\">DSGet<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/CommandLine\">CommandLine<br \/><\/a><\/div>\n<div style=\"margin: 0px; padding: 0px; display: inline;\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:370abf72-53b5-47ab-acbf-53575c99db23\" class=\"wlWriterSmartContent\">del.icio.us tags: <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/Scripting\">Scripting<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/CLI\">CLI<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/ActiveDirectory\">ActiveDirectory<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/DSQuery\">DSQuery<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/DSGet\">DSGet<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/CommandLine\">CommandLine<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Recently I was helping out in a scripting forum. The topic was getting a report of all groups and their members. I have several VBScripts to do this, but an even easier and faster way is to use the DSQuery and DSGet commands from the command line.  Want to see all the groups in your domain or forest simply run&#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[18],"tags":[],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-batchcmd"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}