{"id":125,"date":"2012-02-20T17:37:36","date_gmt":"2012-02-20T17:37:36","guid":{"rendered":"http:\/\/blogs.oucs.ox.ac.uk\/nexus\/?p=125"},"modified":"2012-02-20T17:41:52","modified_gmt":"2012-02-20T17:41:52","slug":"migration-reporting","status":"publish","type":"post","link":"https:\/\/blogs-new.it.ox.ac.uk\/nexus\/2012\/02\/20\/migration-reporting\/","title":{"rendered":"Migration reporting"},"content":{"rendered":"<p>One of the jobs that&#8217;s fallen to me is to report on the successes (or otherwise) of our mailbox migrations. The output needs to get to people who may not have access to any of the Exchange management tools. Now my PowerShell isn&#8217;t great but with a bit of effort I trawled through my notes and beat some of my old script notes into shape as the scrap of Powershell you see below.<\/p>\n<p>What it does is load up the Exchange snap-in first (so that Exchange commands will be understood), creates a text file listing the successfully migrated mailboxes and then emails it out to the recipient of your choice. In our case I added further recipients on separate lines so that it could also log a ticket in our support system. This allowed our helpdesk to get a record of the migrations without needing access to a server.<\/p>\n<blockquote><p>Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010 -erroraction silentlyContinue<br \/>\n$file = &#8220;C:\\migsuccess.txt&#8221;<br \/>\n$mailboxdata = (Get-MoveRequest | Get-MoveRequestStatistics | where {$_.status -match &#8220;Completed&#8221;} |ft alias, TotalItemSize, TotalMailboxItemCount, PercentComplete, BytesTransferred, ItemsTransferred -auto)<br \/>\n$mailboxdata | out-file &#8220;$file&#8221;<br \/>\nStart-Sleep -s 5<br \/>\n$smtpServer = &#8220;<strong><span style=\"color: #ff0000\">&lt;Hub Transport Server&gt;<\/span><\/strong>&#8221;<br \/>\n$att = new-object Net.Mail.Attachment($file)<br \/>\n$msg = new-object Net.Mail.MailMessage<br \/>\n$smtp = new-object Net.Mail.SmtpClient($smtpServer)<br \/>\n$msg.From = &#8220;<span style=\"color: #ff0000\"><strong><span style=\"color: #ff0000\">&lt;from@address.com&gt;<\/span><\/strong><\/span>&#8221;<br \/>\n$msg.To.Add(&#8220;<span style=\"color: #ff0000\"><strong><span style=\"color: #ff0000\">&lt;your email@address.com&gt;<\/span><\/strong><\/span>&#8220;)<br \/>\n$msg.Subject = &#8220;Migration Report: Successes&#8221;<br \/>\n$msg.Body = &#8220;Dear Migration Watcher,&#8221;+&#8221;`r `n&#8221;+&#8221;Attached to this email is a daily report which lists all of the mailboxes which SUCCEEDED in their migration to Exchange 2010.&#8221;+&#8221;`n&#8221;+&#8221;These have been committed to the Exchange 2010 servers in full, without logging an error. The mailboxes&#8217; content should therefore be unaltered, simply having been transferred in full to an Exchange 2010 server.&#8221;+&#8221;`r `n&#8221;+&#8221;Kind regards&#8221;+&#8221;`n&#8221;+&#8221;`r `n&#8221;+&#8221;OUCS Nexus Team&#8217;s friendly automessenger&#8221;<br \/>\n$msg.Attachments.Add($att)<br \/>\n$smtp.Send($msg)<br \/>\n$att.Dispose()<\/p><\/blockquote>\n<p>The actual command I used generated four reports rather than just listing the successful ones (substitute &#8216;Failed&#8217;, &#8216;Completed with error&#8217; or &#8216;autosuspended&#8217; \u00a0for &#8216;completed&#8217; on the third line). One of the downsides of reusing old bits of PowerShell, rather than starting from scratch each time, is that this bit has to supply codes (&#8216;<span style=\"color: #ff0000\">`r<\/span>&#8216; and &#8216;<span style=\"color: #ff0000\">`n<\/span>&#8216;) to generate the paragraph\/new lines within the email. Nowadays I would probably make the body text of the e-mail a Powershell &#8216;here&#8217; string so that the format matches what&#8217;s in the script. That makes it more readable \/maintainable while also offering scope for the use of parameters (such as <em><span style=\"color: #808080\">$($mbox.DisplayName)<\/span><\/em> for personalising the &#8216;Dear User&#8217; line). This was first written back in the days when I was still using Notepad as my editor&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the jobs that&#8217;s fallen to me is to report on the successes (or otherwise) of our mailbox migrations. The output needs to get to people who may not have access to any of the Exchange management tools. Now &hellip; <a href=\"https:\/\/blogs-new.it.ox.ac.uk\/nexus\/2012\/02\/20\/migration-reporting\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":107,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs-new.it.ox.ac.uk\/nexus\/wp-json\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs-new.it.ox.ac.uk\/nexus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs-new.it.ox.ac.uk\/nexus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs-new.it.ox.ac.uk\/nexus\/wp-json\/wp\/v2\/users\/107"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs-new.it.ox.ac.uk\/nexus\/wp-json\/wp\/v2\/comments?post=125"}],"version-history":[{"count":4,"href":"https:\/\/blogs-new.it.ox.ac.uk\/nexus\/wp-json\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":127,"href":"https:\/\/blogs-new.it.ox.ac.uk\/nexus\/wp-json\/wp\/v2\/posts\/125\/revisions\/127"}],"wp:attachment":[{"href":"https:\/\/blogs-new.it.ox.ac.uk\/nexus\/wp-json\/wp\/v2\/media?parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs-new.it.ox.ac.uk\/nexus\/wp-json\/wp\/v2\/categories?post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs-new.it.ox.ac.uk\/nexus\/wp-json\/wp\/v2\/tags?post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}