title: Backup multiple groups with their members
body: <p>I would like to make a backup of all the groups -like DEP_Fin_* (I have about 30 groups). I would like to generate an excel or csv backup file for each groups. The name of each backup files must be the ADGroup name. When I run the script I only have one backup file... can you help me with this?</p>
  <pre><code>$Path = &quot;C:\Temp\$($group.Name).xlsx&quot;
  $adgroup = Get-ADGroup -filter {Name -like &quot;DEP_Fin_*&quot;} -Properties Name
  
  
  $result = foreach($group in $ADGroup) {
  
  Get-ADGroupMember -Identity $group.Name | Where-Object {
          $_.objectclass -eq &quot;user&quot;
      } | Select DisplayName, SamAccountName
       }
  
  
  $Result | Export-Excel -Path $Path
  </code></pre>