Site Tools


export_einer_mailbox

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

export_mailbox.ps1
<#
 
.SYNOPSIS
This is a simple Powershell script to export the Mailbox from one Account
 
.DESCRIPTION
The script will export the Mailbox from a selected Account to a Networkdrive.
 
.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 to be exported'
#$User2 = Read-Host -Prompt 'UserID of Account to be imported'
 
$Servername = "Servername"
$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
 
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"
 
$Mailbox = (get-aduser $User1 -Properties CanonicalName).CanonicalName
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 "yellow"
 
Get-MailboxExportRequest -status Completed | Remove-MailboxExportRequest -Confirm:$False
 
Write-Host "Completed Exportjob deleted" -foreground "yellow"
export_einer_mailbox.txt · Last modified: 2017/01/17 10:43 by clemens