title: Output a list of AD users, with group names starting with *ABC*
body: <p>How can I get a single file(csv or txt) with the name of each group with the members listed underneath. </p>
  
  <p>The groups all start with "ABC" for example.</p>
  
  <p>Here is my code which gives me exactly what I want output to the console, however, when I output to CSV I am not able to append the group name, and only am able to get the members.</p>
  
  <pre><code>import-module activedirectory
  $Groups = Get-ADGroup -filter {Name -like "ABC*"} | Select-Object Name
  
  ForEach ($Group in $Groups)
     {
      write-host " "
      write-host "$($group.name)"
      Get-ADGroupMember -identity $($group.name) -recursive | Select-Object Name
     }
  </code></pre>
  
  <p>The code above gives me a nice output on the console that's laid out like:</p>
  
  <p><strong>Group ABC1</strong>
  <br>Person1<br>
  Person2<br>
  Person3<br>
  Person4<br></p>
  
  <p><strong>Group ABC2</strong>
  <br>Person1<br>
  Person2<br>
  Person3<br>
  Person4<br></p>
  
  <p><br><br>
  How can I have this output into a text or csv file keeps the layout and format as above?</p>