{"id":4314,"date":"2019-09-08T23:07:44","date_gmt":"2019-09-08T23:07:44","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=4314"},"modified":"2019-09-08T23:07:44","modified_gmt":"2019-09-08T23:07:44","slug":"powershell-script-to-export-exchange-mailbox-to-smaller-pst-chunks","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/powershell-script-to-export-exchange-mailbox-to-smaller-pst-chunks","title":{"rendered":"Powershell Script to Export Exchange mailbox to smaller PST Chunks"},"content":{"rendered":"<p>Powershell Script to Export Exchange mailboxes in 20GB PST allotments for upload to Mimecast<\/p><p>&nbsp;<\/p><p>[pastacode lang=&#8221;markdown&#8221; manual=&#8221;Import-Module%20activedirectory%0A%0A%24TargetUserName%3D%22jsmith%22%0A%24Useremail%3D%22jsmith%40domain.com%0A%24Location%20%3D%20%22%5C%5C10.1.10.18%5CArchiveExport%5C%22%0A%0A%24FirstEmail%20%3D%20Get-MailboxFolderStatistics%20%24TargetUserName%20-IncludeOldestAndNewestItems%20%7C%20%3F%20%7B%24_.OldestItemReceivedDate%7D%20%7C%20Sort-Object%20OldestItemReceivedDate%20%7C%20Select%20-ExpandProperty%20OldestItemReceivedDate%20-First%201%0A%24FirstEmail%20%3D%20%24FirstEmail.ToString(%22MM%2Fdd%2Fyyyy%22)%0A%0A%24finish%20%3D%20%24FirstEmail%0A%0A%23The%20end%20date%20of%20when%20the%20last%20email%20wants%20to%20be%20exported%20%2C%20if%20using%20Mimecast%20this%20will%20be%20the%20date%20of%20enabling%20archiving%0A%24startdate%20%3D%20Get-Date%0A%0A%24startofmonth%20%3D%20Get-Date%20%24startdate%20-day%201%20-hour%200%20-minute%200%20-second%200%0A%0A%24endofmonth%20%3D%20((%24startofmonth).AddMonths(1).AddSeconds(-1))%0A%0A%24pstnumber%20%3D%201%0A%0Ado%20%7B%0A%24startvalue%20%3D%20Get-Date%20-format%20d%20-Date%20%24startofmonth%0A%0A%24endvalue%20%3D%20Get-Date%20-format%20d%20-Date%20%24endofmonth%0A%0ANew-MailboxExportRequest%20%24TargetUserName%20-ContentFilter%20%22((Received%20-gt%20&#8217;%24startofmonth&#8217;)%20-and%20(Received%20-lt%20&#8217;%24endofmonth&#8217;))%22%20-FilePath%20%24Location%24Useremail%22.pst%22%20-Confirm%3A%24false%0A%0A%24ExportStats%20%3D%20Get-MailboxExportRequest%20-Mailbox%20%24TargetUserName%0A%24ExportStatus%20%3D%20%24ExportStats.Status%0A%0ADo%7B%0AStart-Sleep%2010%0A%24ExportStats%20%3D%20Get-MailboxExportRequest%20-Mailbox%20%24TargetUserName%0A%24ExportStatus%20%3D%20%24ExportStats.Status%0A%7D%20while%20(%24ExportStatus%20-eq%20%22Queued%22%20-or%20%24ExportStatus%20-eq%20%22InProgress%22)%0A%0AStart-Sleep%2030%0A%0AGet-MailboxExportRequest%20-mailbox%20%24targetusername%20-Status%20%22Completed%22%20%7C%20Remove-MailboxExportRequest%20-Confirm%3A%24false%0A%0AStart-Sleep%2030%0A%0Aif((Get-Item%20%24Location%24useremail%22.pst%22).length%20-gt%2020gb)%20%7B%0ARename-Item%20%24Location%24Useremail%E2%80%9D.PST%E2%80%9D%20%24Location%24Useremail%E2%80%9D.%E2%80%9C%24pstnumber%E2%80%9D.PST%E2%80%9D%0A%24pstnumber%2B%2B%0A%7D%0A%0A%24startofmonth%20%3D%20((%24startofmonth).AddMonths(-1))%0A%0A%24endofmonth%20%3D%20((%24startofmonth).AddMonths(1).AddSeconds(-1))%0A%0AStart-Sleep%2030%0A%0A%7D%0A%0Awhile%20(%24startofmonth%20-ge%20%24finish)%0A&#8221; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]<\/p>","protected":false},"excerpt":{"rendered":"<p>Powershell Script to Export Exchange mailboxes in 20GB PST allotments for upload to Mimecast&nbsp;[pastacode lang=&#8221;markdown&#8221; manual=&#8221;Import-Module%20activedirectory%0A%0A%24TargetUserName%3D%22jsmith%22%0A%24Useremail%3D%22jsmith%40domain.com%0A%24Location%20%3D%20%22%5C%5C10.1.10.18%5CArchiveExport%5C%22%0A%0A%24FirstEmail%20%3D%20Get-MailboxFolderStatistics%20%24TargetUserName%20-IncludeOldestAndNewestItems%20%7C%20%3F%20%7B%24_.OldestItemReceivedDate%7D%20%7C%20Sort-Object%20OldestItemReceivedDate%20%7C%20Select%20-ExpandProperty%20OldestItemReceivedDate%20-First%201%0A%24FirstEmail%20%3D%20%24FirstEmail.ToString(%22MM%2Fdd%2Fyyyy%22)%0A%0A%24finish%20%3D%20%24FirstEmail%0A%0A%23The%20end%20date%20of%20when%20the%20last%20email%20wants%20to%20be%20exported%20%2C%20if%20using%20Mimecast%20this%20will%20be%20the%20date%20of%20enabling%20archiving%0A%24startdate%20%3D%20Get-Date%0A%0A%24startofmonth%20%3D%20Get-Date%20%24startdate%20-day%201%20-hour%200%20-minute%200%20-second%200%0A%0A%24endofmonth%20%3D%20((%24startofmonth).AddMonths(1).AddSeconds(-1))%0A%0A%24pstnumber%20%3D%201%0A%0Ado%20%7B%0A%24startvalue%20%3D%20Get-Date%20-format%20d%20-Date%20%24startofmonth%0A%0A%24endvalue%20%3D%20Get-Date%20-format%20d%20-Date%20%24endofmonth%0A%0ANew-MailboxExportRequest%20%24TargetUserName%20-ContentFilter%20%22((Received%20-gt%20&#8217;%24startofmonth&#8217;)%20-and%20(Received%20-lt%20&#8217;%24endofmonth&#8217;))%22%20-FilePath%20%24Location%24Useremail%22.pst%22%20-Confirm%3A%24false%0A%0A%24ExportStats%20%3D%20Get-MailboxExportRequest%20-Mailbox%20%24TargetUserName%0A%24ExportStatus%20%3D%20%24ExportStats.Status%0A%0ADo%7B%0AStart-Sleep%2010%0A%24ExportStats%20%3D%20Get-MailboxExportRequest%20-Mailbox%20%24TargetUserName%0A%24ExportStatus%20%3D%20%24ExportStats.Status%0A%7D%20while%20(%24ExportStatus%20-eq%20%22Queued%22%20-or%20%24ExportStatus%20-eq%20%22InProgress%22)%0A%0AStart-Sleep%2030%0A%0AGet-MailboxExportRequest%20-mailbox%20%24targetusername%20-Status%20%22Completed%22%20%7C%20Remove-MailboxExportRequest%20-Confirm%3A%24false%0A%0AStart-Sleep%2030%0A%0Aif((Get-Item%20%24Location%24useremail%22.pst%22).length%20-gt%2020gb)%20%7B%0ARename-Item%20%24Location%24Useremail%E2%80%9D.PST%E2%80%9D%20%24Location%24Useremail%E2%80%9D.%E2%80%9C%24pstnumber%E2%80%9D.PST%E2%80%9D%0A%24pstnumber%2B%2B%0A%7D%0A%0A%24startofmonth%20%3D%20((%24startofmonth).AddMonths(-1))%0A%0A%24endofmonth%20%3D%20((%24startofmonth).AddMonths(1).AddSeconds(-1))%0A%0AStart-Sleep%2030%0A%0A%7D%0A%0Awhile%20(%24startofmonth%20-ge%20%24finish)%0A&#8221; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4314","post","type-post","status-publish","format-standard","hentry","category-research"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/4314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=4314"}],"version-history":[{"count":1,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/4314\/revisions"}],"predecessor-version":[{"id":4315,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/4314\/revisions\/4315"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=4314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=4314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=4314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}