Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Old Exchange Script to Office 365 Exchange

$
0
0

Previously, I was using the script (on our old Exchange server) below to create a report on all emails sent to a different domain name aside from our company's registered domains. Now, we are using Office 365 and I don't know how to make this work.

Here is my script for collecting emails not sent to our company's registered domains:

Get-MessageTrackingLog -ResultSize Unlimited -EventID "SEND" | where{$_.recipients -notlike "*@company.com, *@company-1.com"} |select-object Timestamp,Source,EventId,Sender,{$_.Recipients},MessageSubject | Format-Table -Wrap -AutoSize| Out-File -FilePath "X:\EmailLogs\EmailLog $(get-date -f yyyy-MM-dd).txt" -width 1000

Now this is the second script I use to "pull" the logs and send emails for notification:

  $date = Get-Date -Format d.MMMM.yyyy
  $source = "X:\EmailLogs\EmailLog $(get-date -f yyyy-MM-dd).txt"
  $destination = "\\Company-Shared\EmailLogs\"
  $path = test-Path $destination

  $smtp = "EXCH01"
  $from = "Sender <sender@company.com>"
  $to = "Recipient <recipient@company.com>"
  $body = "This is a scheduled-automated e-mail message. Exchange Log file copied to \\Company-Shared\EmailLogs shared folder: $date"
  $subject = "Exchange Log Backup on $date" 

  if ($path -eq $true) {
             copy-Item  -Path $source -Destination $destination
             $backup_log = Dir -Recurse $destination | out-File "$destination\backup_log.txt"
             $attachment = "$destination\backup_log.txt"
             send-MailMessage -SmtpServer $smtp -From $from -To $to -Subject $subject -Body $body -BodyAsHtml
             send-MailMessage -SmtpServer $smtp -From $from1 -To $to1 -Subject $subject1 -Attachments $attachment -Body $body1 -BodyAsHtml
             write-host "Copy Sucessfull"
  }

How can I make this work for our new Office365?

Thank you.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>