{"id":2714,"date":"2018-11-08T10:09:22","date_gmt":"2018-11-08T08:09:22","guid":{"rendered":"https:\/\/msb365.abstergo.ch\/?p=2714"},"modified":"2023-06-23T13:08:01","modified_gmt":"2023-06-23T11:08:01","slug":"import-pst-files-using-exchange-powershell","status":"publish","type":"post","link":"https:\/\/www.msb365.blog\/?p=2714","title":{"rendered":"Import PST files using Exchange PowerShell"},"content":{"rendered":"<p>If we want to import PST files into an Exchange mailbox, we can use the PowerShell CMDlet <span style=\"color: #999999;\"><em>New-MailboxImportRequest<\/em><\/span>. The PST files that we want to import must be available through a file share, because the CMDlets <span style=\"display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: Georgia,'Times New Roman','Bitstream Charter',Times,serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;\">only <\/span>accept UNC paths. To import a PST file, we use the following command:<\/p>\n<pre>New-MailboxImportRequest -Mailbox 'Name of Mailbox' -FilePath 'UNC-path of the PST-file'<\/pre>\n<p>To show this in a real example:<\/p>\n<pre>New-MailboxImportRequest -Mailbox drpe -FilePath \\\\ExC2019\\transfer\\outlook1.pst<\/pre>\n<p>With this command we import the complete contents of the PST file. However, If we use the <span style=\"color: #999999;\"><em>-verbose<\/em> <\/span>option, we will get more information during the import and it helps to find errors faster.<\/p>\n<p>If we receive an error, we can use the <span style=\"color: #999999;\"><em>Get-ManagementRoleAssignment -RoleAssignee &lt;group or user&gt;<\/em> <\/span>command to verify that the user with whom we are running the command has the Mailbox Import Export rights. In addition, the appropriate destination mailbox must exist. We can verify this behavior by using the <span style=\"color: #999999;\"><em>get-mailbox -Identity &lt;name&gt;<\/em> command.<\/span><\/p>\n<p>With the command <span style=\"color: #999999;\"><em>get-mailbox -identity &lt;name&gt; | get-mailboxpermission<\/em><\/span>\u00a0we can verify that we have sufficient rights on the mailbox. The two CMDlets <span style=\"color: #999999;\"><em>Get-MailboxImportRequest<\/em><\/span> and <span style=\"color: #999999;\"><em>Get-MailboxImportRequestStatistics<\/em><\/span> provide real-time information about import processes. With these CMDlets we can also use pipes to get more detailed information, like the current status of\u00a0<span style=\"display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: Georgia,'Times New Roman','Bitstream Charter',Times,serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;\">an import request<\/span> , its progress in percent and even to get a complete report for a request.<\/p>\n<pre>Get-MailboxImportRequest 'Name of import request| fl<\/pre>\n<pre class=\"lang:default decode:true\">Get-MailboxImportRequest 'Name of import request| Get-MailboxImportRequestStatistics<\/pre>\n<p>With this, you can easily build a &#8220;do&#8230;until&#8221; loop which waits until the import request has completed and then executes further actions.<\/p>\n<p>In the following example, the do until loop checks and shows the current status of a request every 5 seconds and will send a notification e-mail, including the request report once it has completed.<\/p>\n<pre class=\"lang:default decode:true \" title=\"wait until completed - by Dominic Manning\">$reqname = 'Name of import request'\r\n$report = 'path for report file to be saved to'\r\n\r\n#do...until loop\r\ndo{\r\n    cls\r\n    $reqstat = Get-MailboxImportRequest $reqname |Get-MailboxImportRequestStatistics\r\n    \"Import request $reqname is running. Percent completed:  $($status.PercentComplete)%\"\r\n    sleep -Seconds 5\r\n    }\r\nuntil($reqstat.Status -eq \"Completed\" -or $reqstat.Status -eq \"Failed\" -or $reqstat.Status -eq \"CompletedWithWarning\")\r\n\r\n#save the request report to file\r\nGet-MailboxImportRequest $reqname | Get-MailboxImportRequestStatistics -IncludeReport | fl &gt; $report\r\n\r\n#send an email with status info and the request report as attachement\r\nSend-MailMessage -Body \"Import request $reqname finished with status $($reqstat.Status).\" -From 'sender email' -to 'recipient email' -SmtpServer 'smtp server address' -Subject \"PST import completed\" -Attachments $report<\/pre>\n<p>After an import request has been completed, we need to delete the entry of this import request. To do so, we use the CMDlet <span style=\"color: #999999;\"><em>Remove-MailboxImportRequest<\/em><\/span>.<\/p>\n<p>By the way, in addition to the ability to import a complete PST file, we <span style=\"display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: Georgia,'Times New Roman','Bitstream Charter',Times,serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;\">can <\/span>also select only individual folders to be imported. This is done by using the <em>-IncludeFolders<\/em> parameter. Only the specified folders will be imported and all other folders will be ignored from the import. Following, the complete command.<\/p>\n<pre class=\"lang:default decode:true \">New-MailboxImportRequest -Mailbox 'name' -FilePath 'UNC-path of the PST-file' -IncludeFolders 'Name of the folder inside the PST-file'<\/pre>\n<p>If we want to import all folders and omit individual ones, we can use the <span style=\"color: #999999;\"><em>-ExcludeFolders<\/em> <\/span>option. With the option <span style=\"color: #999999;\"><em>-ExcludeDumpster<\/em> <\/span>we exclude the recycle bin from the import.<\/p>\n<p>However, we can also specify the destination folder in the mailbox where the CMDlet should import the data:<\/p>\n<pre>New-MailboxImportRequest -Mailbox 'name' -FilePath 'UNC-path of the PST-file' -TargetRootFolder 'Folder in mailbox'<\/pre>\n<p>If the specified folder is not present inside of the mailbox, it will automatically be created by the CMDlet. The IsArchive switch will make the wizard import the PST file into the user&#8217;s archive.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Photo by\u00a0<a href=\"https:\/\/unsplash.com\/photos\/sxNt9g77PE0?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\">Erda Estremera<\/a>\u00a0on\u00a0<a href=\"https:\/\/unsplash.com\/search\/photos\/moving?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\">Unsplash<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If we want to import PST files into an Exchange mailbox, we can use the PowerShell CMDlet New-MailboxImportRequest. The PST files that we want to import must be available through a file share, because the CMDlets only accept UNC paths. To import a PST file, we use the following command: New-MailboxImportRequest -Mailbox &#8216;Name of Mailbox&#8217; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2721,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[1923,2],"tags":[],"class_list":["post-2714","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-365","category-exchange"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/2714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2714"}],"version-history":[{"count":22,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/2714\/revisions"}],"predecessor-version":[{"id":5195,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/2714\/revisions\/5195"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/media\/2721"}],"wp:attachment":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}