Office 365 Move Report

I have been doing a lot of Office 365 lately and I’ve been getting very “tired” of checking the status of mailbox moves at night. I get on the pc, check the status of the moves, then go back to the family. Yea, right…. I check the moves, go to youtube, and 40 mins later my wife asks “Have I lost you again to the box?”

I have to first connect to the cloud with the three magical commands in powershell.

 $O365Cred = Get-Credential
 $O365Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection
 Import-PSSession $O365Session

The script emails me a progress report of mailbox moves every 10 mins. It needs to “relay out”, so I make sure I’m either pointing to the exchange server (or another server) that allows me to do this.

The “how many times it emails me” can be changed by modifying the do-while loop parameter. Currently the loop is set to 5 times. {while ($i -le 6)}
The “how often it emails me” can be changed by modifying the Start-Sleep parameter, which is set to 600 seconds {Start-Sleep -s 600}
Change the smtp server from   $smtpServer = “relay.domain.com”   to the server that will relay for you. Change the From and To addresses to your liking, and you are all set.

I was able to check my live.com email account and see updates from my phone.

Here is the script:

$i = 1
 do {
#Get Statistics on move requests, sort by percent complete
$Moves= Get-MoveRequest | Get-MoveRequestStatistics | select-object Alias, TotalInProgressDuration,PercentComplete| sort-object PercentComplete
$Moves  |ConvertTo-Html |out-file Moves.htm
#So i know what's happening, I have it write to the screen that it's sending mail
Write-Host "Sending Email"
     #SMTP server name
      $smtpServer = "relay.domain.com"
     #Creating a Mail object
      $msg = new-object Net.Mail.MailMessage
     #Creating SMTP server object
      $smtp = new-object Net.Mail.SmtpClient($smtpServer)
     #Email structure 
      $msg.From = "no-reply@domain.com"
      $msg.ReplyTo = "no-reply@domain.com"
      $msg.To.Add("youremail@yourdomain.com")
      $msg.subject = "MoveReport"
      $msg.IsBodyHTML = $true
      $msg.body = get-content .\moves.htm
     #Sending email 
      $smtp.Send($msg)

#Pause for 600 seconds (10 mins) 
Start-Sleep -s 600
 $i++
 }
 while ($i -le 6)
Advertisements

About Mike

owner of blog
This entry was posted in Azure, Migration, Office 365, PowerShell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s