title: Trying to Get a Nested List of Users in a Group in Active PowerShell Directory
body: <p>I am trying to get a list of users in a group in an active directory. We have multiple domains. I want to run it from a central location that will poll each domain for each group. Also, I want it to display nested members as well.</p>
  
  <p>Currently, I tried running this and it sort of worked when the machine was on the same domain as the domain I am polling. All members and nested members get displayed.</p>
  
  <pre><code>dsquery group -samid "group name" | dsget group -members -expand &gt;c:\list.txt
  
  "cn=username,ou=users,dc=domain1,dc=com"
  </code></pre>
  
  <p>But when I try to poll another domain there is no output.</p>
  
  <pre><code>dsquery group -samid "cn=group name,cn=users,dc=domain2,dc=com" | dsget group -members -expand &gt;c:\list.txt
  
  dsget failed: 'target object for this command' is  missing
  </code></pre>
  
  <p>Then if I try it without the same id I get an output.</p>
  
  <pre><code>dsquery group "cn=group name,cn=users,dc=domain2,dc=com" | dsget group -members -expand &gt;c:\list.txt
  
  "CN=username2,OU=users,DC=domain2,DC=com"
  "CN=S-1-5-21,CN=ForeignSecurityPrincipals,DC=domain1,DC=com"
  "cn=group name,ou=users,dc=domain2,dc=com"
  </code></pre>
  
  <p>So I get ids and it is not showing the nested members.</p>
  
  <p>What can I do to get it to resolve the correct nested members and non-sids? Also, how would I go about making it poll multiple group names in multiple domains? Or should I just separate it all out and do one at a time?</p>
  
  <p>Thanks in advance!</p>