New-MailboxImportRequest raising “Error details: Access to the path is denied”

Importing PSTs to an Exchange on-premises mailbox is a cool feature because it helps you to get rid of old legacy PSTs which can cause you a lot of trouble (e.g. corrupted because saved on a network share, accidentially deleted because of hardware switch, etc etc etc).

But sometimes the command to start a new import can drive you crazy as well:

New-MailboxImportRequest

Follow the official documentation for this command to see how powerful it is and how to use it. So when you execute the command you may face the following error:

newmailboximportrequesterror

The error text says:

Unable to open PST file '\\SERVER\c$\Exported PSTs\PSTNAME.pst'. Error details: Access to the path
'\\SERVER\c$\Exported PSTs\PSTNAME.pst' is denied.
 + CategoryInfo : NotSpecified: (:) [New-MailboxImportRequest], RemotePermanentException
 + FullyQualifiedErrorId : [Server=EXCHANGESERVER,RequestId=078dc502-aecb-4122-8e22-f96c1c6141f8,TimeStamp=28.11.2017 10:
 34:01] [FailureCategory=Cmdlet-RemotePermanentException] 7B1A4B04,Microsoft.Exchange.Management.RecipientTasks.New
 MailboxImportRequest
 + PSComputerName : EXCHANGESERVER.FQDN

So the next thing you do is to check the permissions on the folder and they normally look like this:

newmailboximportrequestpermissions

If you read the official documentation very careful, there is a small hint:

You need to grant the following permission to the group Exchange Trusted Subsystem to the network share where you want to export or import PST files:

  • To import PST files from the share: Read permission
  • To save exported PST files to the share: Read/Write permission.

If you don’t grant this permission, you will receive an error message stating that Exchange is unable to establish a connection to the PST file on the network share.

Oh looks like reading the documentation was a good idea, because now the request is being created and the import starts. I personally prefer sharing the folder directly with a $-share. Don’t forget to edit the folder permissions and the sharing permissions. In my case it only worked when I set both:

newmailboximportrequestsuccess

This permission may not be set for a variety of reasons, e.g. a topology with many ActiveDirectory Domains where Exchange is installed in one of the domains, an interrupted permission inheritance or similar.

No matter where it comes from, now you know how to fix it. Happy importing 🙂

Use PowerShell to fill Exchange Mailbox(es) with data

Sometimes you have the need to fill up an Exchange Mailbox up to a certain level, e.g. to test migration speeds. In this post you find a tiny script which can do that for you. All you need is a folder with many files in it and a limit which you want to reach for your mailbox.

[CmdletBinding()]
param( 
 [Parameter(Mandatory=$true)][String]$Recipient, 
 [Parameter(Mandatory=$true)][Int32]$SizeInMB, 
 [Parameter(Mandatory=$true)][String]$FilesFolder, 
 [Parameter(Mandatory=$true)][String]$O365Sender
)
$ErrorActionPreference = 'SilentlyContinue'

[Double]$totalsize = 0
[Double]$attsize = 0
$pw = Read-Host ("Please enter the password for " + $O365Sender) -AsSecureString | ConvertFrom-Securestring
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $O365Sender, ($pw | ConvertTo-SecureString)
#$files = Get-ChildItem -Path $FilesFolder -Exclude "*.mp4" -Recurse
$files = Get-ChildItem -Path $FilesFolder -include "*.pptx" -Recurse
$mailcount = 1
while ($totalsize -lt $SizeInMB)
{ 
 $attachment = $files[(Get-Random -Minimum 0 -Maximum ($files.Count - 1))].FullName 
 $attsize = ((Get-Item $attachment).Length / 1000000) 
 $totalsize += $attsize 
 Write-Host ("Sending mail number " + $mailcount.ToString() + "; total size: " + $totalsize.ToString()) 
 Send-MailMessage -From $O365Sender -to $Recipient -Attachments $attachment -SmtpServer smtp.office365.com -Credential $creds -UseSsl -Subject ("Mail number " + $mailcount.ToString() + " via PowerShell script") -port 587 -body "<br><h1>Hallo</h1><br><br>Dies ist eine automatische Mail<br><br>Regards,<br>Your PowerShell Bot" -BodyAsHtml  
 $mailcount++
}

As you see, the script is designed to send mails from an Office 365 Exchange Online Mailbox. It is using the SMTP client submission of Exchange Online. So you are limited to 30 messages per minute (by Nov 17th 2017, this limit may change any time).

The parameters of the script:

  • $recipient: The smtp address of the mailbox which should be filled.
  • $SizeInMB: The amount of data which will be sent. The script counts how many MBs are sent and will stop when it reaches the limit. It doesn’t check the actual mailox size so the result maybe lower because of single instance store technologies or similar.
  • $FilesFolder: The folder with data for the email attachments. The script will pick a random pptx-file from this folder and send it via email. If you’d like other file types than pptx, just change the search filter. I’ve decided for pptx files because they are often large and I have tons of them. If you need tons of files, try the Ignite downloader.
  • $O365Sender: The sign in name of the mailbox from where you want to send the emails.

With some small adjustements you can use the script also with an on-premises mailbox as a sender. Happy mailbox filling 🙂

Feel free to download the script from my GitHub Page: PowerShell-ExchangeOnline GitHub Repository

Create multiple hybrid migration batches with PowerShell

Sometimes in Exchange Online migration projects you have the demand to make not few big batches but many small ones. In the end this means you have many CSV files which you want to use for bulk creation of migration batches.

You can either create them by using the GUI (which is not really fun when you have more than 10 CSV files) or by using this tiny PowerShell command. You have to replace the highlighted values with your own ones:

Get-ChildItem *.csv  | Foreach-Object{ New-MigrationBatch -Name ($_.Name -replace ".csv","") -TargetDeliveryDomain "TENANTNAME.mail.onmicrosoft.com" -AutoStart -AllowUnknownColumnsInCsv $true -NotificationEmails "YOUR.EMAIL@DOMAIN.COM" -CSVData ([System.IO.File]::ReadAllBytes( $_.FullName)) -BadItemLimit 99999 -LargeItemLimit 99999 -AllowIncrementalSyncs $true -SourceEndpoint "NAME OF YOUR HYBRID ENDPOINT"}

 

This command searches for all CSV files in the current folder and creates a migration batch for each CSV file with the following attributes:

  • The name of the batch will be the file name of the CSV file without the file extension
  • The batch will start automatically but has to be completed manually
  • The notification emails will be sent to the email you provide here
  • The CSV files may have any column, but the column “EmailAddress” must be present
  • The batches will perform incremental syncs
  • the LargeItemLimit and BadItemLimit are very high to ensure the mailboxes will not skip because of items that can’t be migrated
  • The hybrid endpoint of your organization will be taken for the move

Of course you may adjust this command depending on your needs, e.g. Auto Completion or a lower BadItemLimit.

In my case there was a limit of 100 migration batches. The Exchange Online Service Description doesn’t mention this limit, but be aware of the fact that this may hit you as well.

Happy migrating 🙂