Site Tools


import_einer_mailbox

Hier findet ihr ein Script um das exportierte pst File eines Accounts in eine Mailbox zu importieren. Der Account wird abgefragt und der Mailboximportjob gestartet und überwacht bis er fertig ist und der verbliebene Job wird vom Exchangesystem gelöscht.

import_mailbox.ps1
<#
 
.SYNOPSIS
This is a simple Powershell script to import an recently exported Mailbox
 
.DESCRIPTION
The script will first export the Mailbox from a selected old Account to a Networkdrive
and the Import it to the Users new Account, so the User will have it´s old Mails in his new Account.
 
.EXAMPLE
./export_import_mailbox.ps1
 
.NOTES
You have to enter the UserID to exported first
Then enter the UserID of Account in wich to Import it.
 
.LINK
http://www.clemens-bayer.de/
 
#>
 
 
 
$User1 = Read-Host -Prompt 'UserID of Account that was exported'
$User2 = Read-Host -Prompt 'UserID of Account to be imported'
 
$date = (Get-Date).ToString("_yyyyMMdd")
$Servername = "Name des Quellservers"
 
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
 
#Defining Source and Destination path
 
$DestPath = "\\$Servername\UserExport$\$date\$User1"
#$Mailbox = (get-aduser $User1 -Properties CanonicalName).CanonicalName
$Mailbox2 = (get-aduser $User2 -Properties CanonicalName).CanonicalName
 
 
New-MailboxImportRequest -FilePath "$DestPath\mailboxexport_$User1.pst" -Mailbox $User2
# -TargetRootFolder "$User2"
 
Write-Host "Mailboximport is getting done from File: "$DestPath\mailboxexport_$user1.pst" to Mailbox $User2" -foreground "yellow"
 
 
if ($Time) {clear-variable -name Time}
$Time = (Get-Date).ToLongTimeString()
 
do
	{
	$checkcompleted = Get-MailboxImportRequest -Mailbox $Mailbox2 -Status completed
	start-sleep -s 10
	if(!$checkcompleted) 
		{
                Write-Host "Import is still running" -foreground "yellow"
		} 
		}
until($checkcompleted)
 
 
Write-Host "Mailboximport is done to Mailbox $User2" -foreground "green"
import_einer_mailbox.txt · Last modified: 2017/01/17 10:43 by clemens