Site Tools


export_und_import_einer_mailbox

Hier findet ihr ein Script um die Mailbox eines Accounts in ein pst File zu exportieren und danach in einen Anderen Account zu importieren. Die Accounts werden abgefragt und die Jobs gestartet und überwacht bis sie fertig sind und der verbliebenen Jobs werden vom Exchangesystem gelöscht.

export-import_mailbox.ps1
<#
 
.SYNOPSIS
This is a simple Powershell script to export the Mailbox from one Account and import it to another Account
 
.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://wiki.clemens-bayer.de/
 
#>
 
 
 
$User1 = Read-Host -Prompt 'UserID of Account to be exported'
$User2 = Read-Host -Prompt 'UserID of Account to be imported'
 
$Servername = "Name des Quellservers"
$date = (Get-Date).ToString("_yyyyMMdd")
 
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-Item -Path $DestPath -ItemType directory
 
#Creating new folder for storing backup
 
Write-Host "Set Permissions on Destinationfolder" -foreground "yellow"
$ACL = Get-Acl "$DestPath"
$ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("deutscheleasing.de\Exchange Trusted Subsystem","FullControl","ContainerInherit, ObjectInherit", "None", "Allow")))
Set-Acl "$DestPath" $ACL
 
Write-Host "Start MailboxexportRequest" -foreground "yellow"
New-MailboxExportRequest -Mailbox $User1 -FilePath "$DestPath\mailboxexport_$User1.pst"
Write-Host "Mailboxexport is getting done to File: "$DestPath\mailboxexport_$user1.pst"" -foreground "yellow"
 
 
Get-MailboxExportRequest -Mailbox $Mailbox -Status completed
 
 
if ($Time) {clear-variable -name Time}
$Time = (Get-Date).ToLongTimeString()
 
do
	{
	$checkcompleted = Get-MailboxExportRequest -Mailbox $Mailbox -Status completed
	start-sleep -s 10
	if(!$checkcompleted) 
		{
                Write-Host "Export is still running" -foreground "yellow"
		} 
		}
until($checkcompleted)
 
Write-Host "Mailboxexport is done, we have to wait a Moment" -foreground "green"
 
Get-MailboxExportRequest -status Completed | Remove-MailboxExportRequest -Confirm:$False
 
Write-Host "Completed Exportjob deleted" -foreground "yellow"
 
 
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"
export_und_import_einer_mailbox.txt · Last modified: 2017/01/17 10:44 by clemens