title: Get Office 365 users with a specific domain via Powershell
body: <p>I am looking for a way to export a list of users from our Office 365 tenant.</p>
  
  <p>I have tried like below :</p>
  
  <pre><code>Get-MSOLUser -All | Where-Object {$_.IsLicensed -eq $true -and $_.BlockCredential -eq $false} | Select-Object  FirstName, LastName, UserPrincipalName, @{Name=’Licenses’;Expression={[string]::join(“;”, ($_.Licenses))} -Expand Proxyaddresses | ? {$_ -cmatch '^SMTP\:.*@domain.onmicrosoft.com'} | Export-Csv C:\Users\Admin\Desktop\Userlist.csv
  </code></pre>
  
  <p>Output : </p>
  
  <pre><code>#TYPE System.String
  "FirstName","LastName","UserPrincipalName","Licenses","Length"
  "mailbox2",,"mailbox2@domain.onmicrosoft.com","Microsoft.Online.Administration.UserLicense","48"
  </code></pre>
  
  <p>My desired output :</p>
  
  <pre><code>"FirstName","LastName","UserPrincipalName","Licenses","Proxyaddresses"
  "mailbox",,"mailbox@domain.onmicrosoft.com","aksigorta365:STANDARDPACK","mailbox2@domain.onmicrosoft.com"
  </code></pre>