title: how to list users and the groups they are part of in office 365 powershell
body: <p>i need a script please  to export users in office 365 and the groups they are part of and not the other  way around. can anyone help please. all answers i found were to export distribution groups and their members.</p>
  <p>i tried using the below but i dont know how to select group names.</p>
  <p><code>get-mailbox | ? {$_.PrimarySMTPAddress -like &quot;*domain.com&quot;} | Select DisplayName,Alias,PrimarySMTPAddress'</code></p>
  <p>and i tried this too</p>
  <p><code>get-mailbox | ? {$_.PrimarySMTPAddress -like &quot;*domain.com&quot;} | Sort Name | % { $MbxDirData = $_ ; Get-MailboxStatistics $_ } | Select DisplayName, @{E={ $MbxDirData.Alias };L='Alias'}, @{E={ $MbxDirData.PrimarySMTPAddress };L='PrimarySMTPAddress'}, @{E={ $_.TotalItemSize.Value + $_.TotalDeletedItemSize.Value };L=&quot;TotalMailboxSize&quot;}</code></p>
  <p>any help is appreciated.</p>