de-DEen-GB
 
rss

Just can't get enough of IT

This blog is about mostly anything in IT. But the primary focuses are Microsoft Technologies like Exchange, Office 365, Azure and Cloud Security.

Exchange Server 2013Exchange Server 2016Description

This script imports multiple PST files located in a single directory into a user mailbox or a user mailbox archive. 

Due to some filename limitations of the New-MailboxImportRequest cmdlet in reagards to the UNC path, the PST filenames are sanitized. Any unsupported (unwanted) character is removed. You can modify the replacement function as needed. This might be necessary as the PST filenames can be used as target folder names during import.

Original filenames:

Filenames before renaming

Renamed filenames:

Filenames after renaming

When using the FilenameAsTargetFolder switch each PST file is imported into a separate target folder.

PST filenames used as target folder

After successfully importing a PST file, the PST can optionally be renamed to .imported. This simplifies a re-run of the script in the case that you a lot of PST files for a user or a large number of files as part of archive solution offboarding process.

NOTE:
This script utilizes the GlobalFunctions PowerShell module for logging. Please prepare your system for the use of the GlobalFunctions module first.

Steps performed:

  1. Sanitize PST filenames
  2. Create new mailbox import request
  3. Monitor status of created import request
    1. When still running, continue monitoring status
    2. When successfully finished, save import request statistics report to log file and continue with next PST
    3. Rename the imported PST file to .imported
    4. When aborted, continue with next PST or exit script

Examples

 

Example PowerShell Output

.\Start-MailboxImport.ps1 -Identity JohnDoe -Archive -FilePath "\\ROBERTKWEISS\e$\PSTImport\JohnDoe" -FilenameAsTargetFolder -BadItemLimit 10 -ContinueOnError -SecondsToWait 90
Note: Script will wait 90s between each status check!
Create New-MailboxImportRequest for user: JohnDoe and file: \\ROBERTKWEISS\e$\PSTImport\JohnDoe\Myoldarchive.pst into the archive. Targetfolder:"Myoldarchive".
Waiting for import JohnDoe-Myoldarchive.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive.pst to be completed. Status: InProgress
Waiting for import JohnDoe-Myoldarchive.pst to be completed. Status: InProgress
Waiting for import JohnDoe-Myoldarchive.pst to be completed. Status: InProgress
Import request JohnDoe-Myoldarchive.pst completed successfully.
Import request JohnDoe-Myoldarchive.pst deleted.
Create New-MailboxImportRequest for user: JohnDoe and file: \\ROBERTKWEISS\e$\PSTImport\JohnDoe\Myoldarchive1.pst into the archive. Targetfolder:"Myoldarchive1".
Waiting for import JohnDoe-Myoldarchive1.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive1.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive1.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive1.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive1.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive1.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive1.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive1.pst to be completed. Status: Queued
Waiting for import JohnDoe-Myoldarchive1.pst to be completed. Status: InProgress
Waiting for import JohnDoe-Myoldarchive1.pst to be completed. Status: InProgress
Waiting for import JohnDoe-Myoldarchive1.pst to be completed. Status: InProgress
Import request JohnDoe-Myoldarchive1.pst completed successfully.
Import request JohnDoe-Myoldarchive1.pst deleted.
Script finished.

Version History

  • 1.0, Initial community release
  • 1.1, log will now be stored in a subfolder (name equals Identity)
  • 1.2, PST file renaming added
  • 1.3, Module ActiveDirectory removed
  • 1.4, AcceptLargeDatalost would now be added if BadItemLimit is over 51
  • 1.5, Parameter IncludeFodlers added
  • 1.6, Parameter TargetFolder added
  • 1.7, Parameter Recurse added
  • 1.8, PST file rename after successful import added

Links

Last updated: 2017-02-02

Follow me

Additional Note

This Powershell script has been optimized using the ISESteroids™ add-on. Learn more about ISESteroidshere.

 

 

Read More »
On February 24, 2016
0 Comment
2700 Views

When you use the Exchange Online Portal to move a cloud mailbox to on-premise (aka Office 365 Offboarding) you can either move

  • Primary Mailbox and the existing Archive
  • Primary Mailbox without moving the Archive

When you select the second option, the move request fails because of the missing archive target delivery domain. The required attribute is not exposed to the Exchange Online Administrative Center.

Office 365 off-boarding

The required option -ArchiveDomain can only be applied when using Remote PowerShell to Exchange Online.

The following lines describe how to move the primary mailbox to your opn-premise Exchange while keeping the archive mailbox in Office 365:

# UPN of user to migrate to Exchange Online
$User = "UserToMigrate@mcsmemail.de"

# FQDN of configured migration endpoint
$RemoteHost = "MigrationEndpoint.mcsmemail.de"

# on-premise target domain 
$TargetDelivery = "mcsmemail.de"

# EOL archive domain
$ArchiveDomain = "TENANT.onmicrosoft.com"

# on-premise target mailbox database name
$TargetDatabase = "MBX-DB01"

# Onpremise credentials to access the target mailbox/on-premise Exchange
$OnPremCred = Get-Credential

# New offboarding move request with automatic completion of the request 
New-MoveRequest -Identity $User -RemoteHostName $RemoteHost -RemoteCredential $OnPremCred -TargetDeliveryDomain $TargetDelivery -ArchiveDomain $ArchiveDomain -PrimaryOnly -SuspendWhenReadyToComplete:$false -Outbound -RemoteTargetDatabase $TargetDatabase

Your scripts can go from here.

Enjoy.

 


You need assistance with your Exchange Server setup? You have questions about your Exchange Server infrastructure and going hybrid? You are interested in what Exchange Server 2016 has to offer for your environment?

Contact me at thomas@mcsmemail.de
Follow at https://twitter.com/stensitzki

Read More »
On January 21, 2016
1 Comment
3092 Views

When you use the Office 365 Portal to move an on-premise mailbox to Office 365 (aka Office 365 Onboarding) you can either move

  • Primary Mailbox and the existing Archive
  • The Archive itself

Screenshot Office 365 Onboarding

There is no option to move only the primary mailbox, if the mailbox already uses a cloud based archive mailbox.

The required option -PrimaryOnly can only be applied when using Remote PowerShell to Exchange Online.

The following lines describe how to move the primary mailbox that does have an enabled cloud archive to Office 365:

# UPN of user to migrate to Exchange Online
$User = "UserToMigrate@mcsmemail.de"

# FQDN of configured migration endpoint
$RemoteHost = "MigrationEndpoint.mcsmemail.de"

# EOL target delivery domain aka tenant domain
$TargetDelivery = "tenant.onmicrosoft.com"

# Onpremise credentials to access the source mailbox
$OnPremCred = Get-Credential

# New onboarding move request
New-MoveRequest -Identity $User -Remote -RemoteHostName $RemoteHost -RemoteCredential $OnPremCred -TargetDeliveryDomain $TargetDelivery -SuspendWhenReadyToComplete:$false -PrimaryOnly

Your scripts can go from here.

Enjoy.

 


You need assistance with your Exchange Server setup? You have questions about your Exchange Server infrastructure and going hybrid? You are interested in what Exchange Server 2016 has to offer for your environment?

Contact me at thomas@mcsmemail.de
Follow at https://twitter.com/stensitzki

Read More »