Skip to content

Scriptless approach to getting information on nested group memberships.

One of the biggest challenges it seems many administrators have is keeping tabs on group membership. This is even more of a problem now that we can nest groups. A popular script is one that queries group memberships recursively. But you don’t need a single line of VBScript. You can get all the information you need with the DSQuery and DSGet commands.
There are two parts to the ultimate solution but I want you to understand how they work. At the command prompt, type:
Dsquery user -samid yourlogonname
You should get the distinguished name of your user object. The beauty of the DS commands is that the output of one command can serve as the input for another. Try this:
Dsquery user -samid yourlogonname | dsget user
You’ll end up with a little more information about your user account. You can use DSGet to return other information, but for our purposes we want to get at group membership. Run this command:
Dsquery user -samid yourlogonname | dsget user -memberof
You should be rewarded with the distinguished names of all the groups the user account belongs to. If you want to check for nested group membership, use a command like this:
Dsquery user -samid yourlogonname | dsget user -memberof -expand
Now you have a longer list of group names. You can’t tell where a group is necessarily nested, but you’ll at least know which group membership is affecting the user. You can also search for more than one user this way:
Dsquery user -limit 0 | dsget user -memberof -expand
This expands the group membership for all user accounts in the domain.
You can also come at this from the group angle:
dsquery group -samid “Sales Staff” | dsget group -members
If you want to expand nested group membership you can use -expand as I did earlier:
dsquery group -samid “Sales Staff” | dsget group -members -expand
By the way, if you don’t know the complete group name, wild cards are allowed:
dsquery group -samid “Sales*” | dsget group -members -expand
Finally, want to build a membership report for all users? Try these commands:
dsquery group –limit 0 >groups.txt for /f “tokens=*” %g in (groups.txt) do @echo %g

>>membership.txt & echo Members: >>membership.txt & dsget group % -members >>membership.txt & echo

**************************************** >>membership.txt

9 Comments Post a comment
  1. if i want to list all users from all groups for an specific OU dsget or dsquery can help me? please let me know, thanks for your time.


    Gian Carlo Poggi

  2. 天然素材 ドリーム 買い物 スポーツシューズ の夢 独特なクッション性 ハンドバッグ [url=]グッチ ハート[/url] 最低価格 割引 素晴らしい ねまき 美しい
    さげもどし あかぎれ ティー セット こんなん リーチ てきしょ あさはか せいあつ ふり かくはん [url=]グッチ シマ[/url] てんぶ マス ゲーム アウトドア スポーツ ぞうかん ふねっしん カレッジ ソング あまみ ようたし
    ニット カジュアルシューズ ウーリー糸 质朴 高品質の製品 自然な高級感 [url=]christian louboutin shoes[/url] 皮革 しんしふく いと 新入荷 魅力 卸売り価格 安い 華奢 上糸
    ミルク いわし じゅみょう ぐうきょ ヘア ブラッシュ [url=]louboutin heels[/url] かみがたえ すねもの とりどり ふてくさる てうち のちぞい じょじゅつ せきばらい さんぴょう しょうしつ

  3. I was wanting to tell this to my frenid the other day. This may cause her end. Subscribed and bookmarked your internet site, maintain the good work.ارسال نظر نام (الزامي) ايميل (الزامي) وبسايت : نظرات شما پس از بررسي و تاييد نمايش داده مي شود.لطفا نظرات خود را فقط در مورد مطلب بالا ارسال کنيد.

  4. This could not possibly have been more helpful!

  5. I really love your site.. Very nice colors & theme.
    Did you build this website yourself? Please reply back as I’m trying to create my own site and would like to
    find out where you got this from or exactly what the theme is called.
    Appreciate it!

  6. Some very good info here. Thx!

  7. I really like the site. I’ve found some
    really good info. Thank you!

  8. I find that somewhere between 35% and 50% yield the best results, but it comes down to personal preference.
    When your teammates are effectively using the mic to plan strategies and update your team on where
    the enemy is, you are more likely to win. NOTE:
    According to the Forest Service, each person may
    pick up to three gallons of berries in a year for personal consumption without a permit.

  9. What’s սp, yeah this post is genuinely pleasant and
    I have learned lot of things from it concerning blogging.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: