title: Get recipient addresses of all messages in exchange online via Powershell
body: <p>I've used a catch-all mailbox so far. I registered every account with a different mail address e.g. stackoverflow.com@mydDomain.de</p>
  
  <p>Since I just switched to O365 I want to create aliases for all accounts so far. I imported all my mails to O365 and I need to get all the recipient-addresses I ever used.</p>
  
  <p>So I need a Powershell Script to loop through all messaages within my O365 Mailsbox to extract the Mail recpient.</p>
  
  <p>I experimented with the get-MessageTrace and it seems to be working:</p>
  
  <pre><code>$dateOBJ = (Get-Date).Adddays(-30);
  $allRecipientsARY = Get-MessageTrace -StartDate $dateOBJ -EndDate (Get-Date) | Group-Object -Property RecipientAddress | Select name
  
  $recipientsARY = @()
  
  ForEach ($recipientSTR in $allRecipientsARY)
  {
      if($recipientSTR -like '*myDomain.com*')
      {
          $recipientsARY = $recipientsARY + $recipientSTR
      }
  }
  
  $recipientsARY | Export-Csv c:\temp\mailAddresses.csv –NoTypeInformation -Encoding UTF8
  </code></pre>
  
  <p>The problem is that the get-MessageTrace function only supports mails 30 days back from current date.</p>
  
  <p>Is there an alternative? So far I haven't found one...</p>
  
  <p>-thx
  Dave</p>