
Hier ist es nun, mein Power Shell GUI Script zum Exportieren von Exchange Postfächern in PST-Dateien!
Diese Seite beinhaltet alle Relevanten Informationen zu dem Script sowie das Change Log. Selbstverständlich kann das Script hier auch als *.zip-Datei heruntergeladen werden :)
[wpfilebase tag=browser id=8/]
#=========================================================================#
# Exchange Server 2010 / 2013 Mailbox-Exporter 1.0 #
# © Andres Sichel // blog.asichel.de // blog@asichel.de #
# Exportiert Exchange Mailboxen in PST-Dateien #
# #
#=========================================================================#
#Für die ausführung muss das Script im STA Modus ausgeführt werden (http://technet.microsoft.com/en-us/magazine/ff629472.aspx)
If ($host.Runspace.ApartmentState -ne 'STA') {
$Script1 = $MyInvocation.MyCommand.Definition
write-host "Script is not running in STA mode. Switching to $Script1"
powershell.exe -ArgumentList -sta -file $Script1
Exit
}
# Ausführungspfad wichtig für die HTML DLL GvS.controls muss im Pfad vom Script liegen
$script:Scriptpath = Split-Path $script:MyInvocation.MyCommand.Path
$script:Recipients_Info_Array = New-Object System.Collections.ArrayList
# Systembibliotheken laden
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.VisualStyles")
# Hauptfensterfenster erstellen
$Icon = [system.drawing.icon]::ExtractAssociatedIcon("$scriptpath\icon.ico")
$Font = New-Object System.Drawing.Font("Arial",10,[System.Drawing.FontStyle]::Regular)
$Fenster1 = New-Object System.Windows.Forms.Form
$Fenster1.Size = New-Object System.Drawing.Size(890,710)
$Fenster1.MaximumSize = "890,310"
$Fenster1.MinimumSize = "890,310"
$Fenster1.Text = "Exchange Server 2010 / 2013 Mailbox-Exporter Version 1.0 © Andres Sichel"
$Fenster1.StartPosition = "CenterScreen"
$Fenster1.BackColor = "#B2E4FF"
$Fenster1.Icon = $Icon
$Fenster1.Font = $Font
# Gruppenboxen ermöglichen das verwenden mehrere Radio-Button Gruppen.
# Zudem ist es leichter die Objekte im Fenster anzuordnen
# Gruppenbox fuer MailboxExport
$GroupBoxExport = New-Object System.Windows.Forms.GroupBox
$GroupBoxExport.Location = New-Object System.Drawing.Size(400,100)
$GroupBoxExport.size = New-Object System.Drawing.Size(465,150)
$GroupBoxExport.Font = $Font
$GroupBoxExport.Text = "Mailbox Exportieren:"
$Fenster1.Controls.Add($GroupBoxExport)
# Gruppenbox fuer Server Benutzer und usw
$GroupBoxEXSrv = New-Object System.Windows.Forms.GroupBox
$GroupBoxEXSrv.Location = New-Object System.Drawing.Size(5,100)
$GroupBoxEXSrv.size = New-Object System.Drawing.Size(380,150)
$GroupBoxEXSrv.Font = $Font
$GroupBoxEXSrv.Text = "Mit Exchange Server verbinden"
$Fenster1.Controls.Add($GroupBoxEXSrv)
# Gruppenbox fuer Benutzer-Mailbox
$GroupBoxMBXAlias = New-Object System.Windows.Forms.GroupBox
$GroupBoxMBXAlias.Location = New-Object System.Drawing.Size(400,10)
$GroupBoxMBXAlias.size = New-Object System.Drawing.Size(465,80)
$GroupBoxMBXAlias.Font = $Font
$GroupBoxMBXAlias.Text = "Mailboxalias angeben"
$Fenster1.Controls.Add($GroupBoxMBXAlias)
# Enter drücken zulassen (nur für Benutzerabfragen)
$Fenster1.KeyPreview = $True
$Fenster1.Add_KeyDown(})
# Mit Escape wird Abmelden ausgeführt und das Fenster wird geschlossen
$Fenster1.Add_KeyDown(})
# Funktionen erstellen
function Anmelden
{
if (!$WindowsUser.Checked)
{
$Fenster1.Cursor = [System.Windows.Forms.Cursors]::WaitCursor
#Am Exchange Server anmelden
#Zertifikatsprüfungen abschalten
$SkipCertificate = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck -Verbose
#Servernamen auslesen
$Server = $ServerName.Text;
#Anmeldedaten erfragen
$cred = Get-Credential
#PS-Session starten --> Bei connection URI den korrekten Exchange 2010 oder 2013 Servernamen eingeben, vorzugsweise CAS-Server
$Session = New-PSSession `
-ConfigurationName Microsoft.Exchange `
-ConnectionUri http://$Server/PowerShell/ `
-Authentication Kerberos `
-SessionOption $SkipCertificate `
-credential $cred `
-Name Exchange
#Importieren der erzeugten Session in die aktuelle Session, lokal gleichlautende Befehle werden ersetzen
Import-PSSession -Session $Session -AllowClobber -Verbose
$Fenster1.Cursor = [System.Windows.Forms.Cursors]::Arrow
if (!$Session.State -eq "open")
{
$AnmledungErg.text = "Anmeldung nicht Erfolgreich"
}
else
{
$AnmledungErg.text ="Erfolgreich angemeldet, los gehts!"
}
}
else
{
$Fenster1.Cursor = [System.Windows.Forms.Cursors]::WaitCursor
#Am Exchange Server anmelden
#Zertifikatsprüfungen abschalten
$SkipCertificate = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck -Verbose
#Servernamen auslesen
$Server = $ServerName.Text;
#Anmeldedaten erfragen
#$cred = Get-Credential
#PS-Session starten --> Bei connection URI den korrekten Exchange 2010 oder 2013 Servernamen eingeben, vorzugsweise CAS-Server
$Session = New-PSSession `
-ConfigurationName Microsoft.Exchange `
-ConnectionUri http://$Server/PowerShell/ `
-Authentication Kerberos `
-SessionOption $SkipCertificate `
-Name Exchange
#Importieren der erzeugten Session in die aktuelle Session, lokal gleichlautende Befehle werden ersetzen
Import-PSSession -Session $Session -AllowClobber -Verbose
$Fenster1.Cursor = [System.Windows.Forms.Cursors]::Arrow
if (!$Session.State -eq "open")
{
$AnmledungErg.text = "Anmeldung nicht Erfolgreich"
}
else
{
$AnmledungErg.text ="Erfolgreich angemeldet, los gehts!"
} }
} #Beende Funktion Anmelden
function Abfrage
{
$Mailbox = $username.text
if (($Username.text.Length -eq 0) -or (!(Get-Recipient $Username.text -ErrorAction SilentlyContinue)))
{
$AnmledungErg.text = "kein Benutzer eingetragen / Benutzer existiert nicht."
}
else {
$Info = Get-MailboxStatistics -Identity $Mailbox
$GroupBoxExport.Text = "Mailbox von " +$Info.DisplayName+ " Exportieren:"
$MailboxSize.Text = "Mailboxgröße: " +$Info.TotalItemSize
$ExportStatusInfo.Text = ""
$ExportProgressBar.Value = 0
}
} # Beendet die Funktion Abfrage
function Export {
$Mailbox1 = $username.text
$ExportPfad = $Speicherort.Text
$BefehlVorhanden = Get-Command New-MailboxExportRequest
if ($BefehlVorhanden.name -eq "New-MailboxExportRequest")
{
$AnmledungErg.text = "Export Befehle geladen"
}
else
{
$KeinBefehl = [Windows.Forms.MessageBox]
$KeinBefehl::Show("Kein Exportbefehl gefunden. Bitte Downloadhinweise bzw. Blog-Post beachten!" , "Befehl nicht vorhanden", "OK", "Error") #New-ManagementRoleAssignment –Role “Mailbox Import Export” –User "DOMAIN\USER"
return 0;
}
if (($Username.text.Length -eq 0) -or (!(Get-Recipient $Username.text -ErrorAction SilentlyContinue)))
{
$MailboxSize.text = "kein Benutzer eingetragen / Benutzer existiert nicht."
}
else {
New-MailboxExportRequest -Mailbox $Mailbox1 -FilePath $ExportPfad -name $Mailbox1
$ExportStatus = Get-MailboxExportRequest -Name $Mailbox1
$ExportStatusInfo.text = $ExportStatus.status
$ExportProgressBar.Style = "Marquee"
$TimerStatus = New-Object System.Windows.Forms.Timer
$TimerStatus.Interval = 500 # sind 4 Stunden (Zahl durch 1000 = Sekunden)
$TimerStatus.add_Tick()
$TimerStatus.start()
}
} # Beendet die Funktion Speichern
function ExportStatusQuery {
$Mailbox1 = $username.text
$ExportStatus = Get-MailboxExportRequest -Name $Mailbox1
if ($ExportStatus.status -eq "Completed")
{
$ExportStatusInfo.text = "Export abgeschlossen"
$ExportStatus | Remove-MailboxExportRequest -Confirm:$false
$ExportProgressBar.Style = "Continuous"
$ExportProgressBar.Value = 100
}
if ($ExportStatus.status -eq "Queued")
{
$ExportStatusInfo.text = "Vorgang wird ausgeführt"
$ExportProgressBar.Style = "Marquee"
}
}
function Abmelden {
Remove-PSSession -Name Exchange
$Ausgabe1.text = "Erfolgreich abgemeldet"
$Fenster1.Close()
} # Beendet die Funktion Abmelden
function PfadAbfrage
{
$PSTSpeichern.ShowDialog()
}
$SpeichernOk =
{
$Speicherort.Text = $PSTSpeichern.FileName
}
# Info-Text Anzeigen lassen
$About1 = New-Object System.Windows.Forms.Label
$About1.Location = New-Object System.Drawing.Size(5,10)
$About1.Size =New-Object System.Drawing.Size(400,35)
$About1.Text = "Exchange Server 2010 / 2013 Mailbox-Exporter Version 1.0
© Andres Sichel // blog.asichel.de // blog@asichel.de"
$Fenster1.Controls.Add($About1)
# Anmeldung erfolgreich Textfeld
$AnmledungErg = New-Object System.Windows.Forms.Label
$AnmledungErg.Location = New-Object System.Drawing.Size(7,25)
$AnmledungErg.Size =New-Object System.Drawing.Size(350,20)
$AnmledungErg.Text = "Anmeldung steht noch aus!"
$GroupBoxEXSrv.Controls.Add($AnmledungErg)
# Eingabefeld für Servernamen bauen
$ServerName = New-Object System.Windows.Forms.Textbox
$ServerName.Location = New-Object System.Drawing.Size(10,60)
$ServerName.Size = New-Object System.Drawing.Size(170,20)
$ServerName.Text = "'Servername im FQDN'"
$ServerName.TabIndex = 1
$GroupBoxEXSrv.Controls.Add($ServerName)
# Anmeldebutton bauen
$Login = New-Object System.Windows.Forms.Button
$Login.Location = New-Object System.Drawing.Size(195,60)
$Login.Size = New-Object System.Drawing.Size(80,22)
$Login.Text = "Anmelden"
$Login.TabIndex = 3
$Login.BackColor = "white"
$Login.Add_Click()
$GroupBoxEXSrv.Controls.Add($Login)
# Abfrage aktuelle Benutzer
$WindowsUser = New-Object System.Windows.Forms.CheckBox
$WindowsUser.Location = New-Object System.Drawing.Size(10,90)
$WindowsUser.Size = New-Object System.Drawing.Size(250,20)
$WindowsUser.Text = "Anmeldung mit aktuellem Benutzer"
$WindowsUser.TabIndex = 2
$GroupBoxEXSrv.Controls.Add($WindowsUser)
# Abmeldebutton bauen
$Abmelden = New-Object System.Windows.Forms.Button
$Abmelden.Location = New-Object System.Drawing.Size(290,60)
$Abmelden.Size = New-Object System.Drawing.Size(80,22)
$Abmelden.Text = "Abmelden"
$Abmelden.TabIndex = 19
$Abmelden.BackColor = "white"
$Abmelden.Add_Click()
$GroupBoxEXSrv.Controls.Add($Abmelden)
# Benutzermailbox angeben
$UserName = New-Object System.Windows.Forms.Combobox
$UserName.Location = New-Object System.Drawing.Size(10,30)
$UserName.Size = New-Object System.Drawing.Size(200,20)
$UserName.Text = "'Username angeben'"
$UserName.TabIndex = 4
$GroupBoxMBXAlias.Controls.Add($UserName)
# Benutzermailbox auflösen
$UsernameAbfragen = New-Object System.Windows.Forms.Button
$UsernameAbfragen.Location = New-Object System.Drawing.Size(240,30)
$UsernameAbfragen.Size = New-Object System.Drawing.Size(80,22)
$UsernameAbfragen.Text = "Auflösen"
$UsernameAbfragen.TabIndex = 5
$UsernameAbfragen.BackColor = "white"
$UsernameAbfragen.Add_Click()
$GroupBoxMBXAlias.Controls.Add($UsernameAbfragen)
#Speicherndialog
$PSTSpeichern = New-Object System.Windows.Forms.SaveFileDialog
$PSTSpeichern.ValidateNames =$false
$PSTSpeichern.CheckPathExists =$true
$PSTSpeichern.Filter = "PST File (*.pst)|*.pst|All Files (*.*)|*.*"
$PSTSpeichern.CreatePrompt = $false
$PSTSpeichern.CheckFileExists = $false
$PSTSpeichern.Title = "Speicherpfad angeben (\\servername\freigabe)"
$PSTSpeichern.DefaultExt = "pst"
$PSTSpeichern.InitialDirectory = "::"; #Systemordner Computer / Dieser PC
$PSTSpeichern.FileName = $Info.DisplayName
$PSTSpeichern.RestoreDirectory = $true
$PSTSpeichern.add_FileOk($SpeichernOk)
#MailboxGröße Textfeld erstellen
$MailboxSize = New-Object System.Windows.Forms.Label
$MailboxSize.Location = New-Object System.Drawing.Size(7,25)
$MailboxSize.Size =New-Object System.Drawing.Size(400,20)
$MailboxSize.Text = ""
$GroupBoxExport.Controls.Add($MailboxSize)
# Pfad
$Speicherort = New-Object System.Windows.Forms.Textbox
$Speicherort.Location = New-Object System.Drawing.Size(10,60)
$Speicherort.Size = New-Object System.Drawing.Size(200,20)
$Speicherort.Text = "'Speicherpfad angeben (UNC)'"
$Speicherort.ReadOnly = $true
$Speicherort.TabIndex = 1
$GroupBoxExport.Controls.Add($Speicherort)
# Pfad-Button
$Pfad = New-Object System.Windows.Forms.Button
$Pfad.Location = New-Object System.Drawing.Size(220,60)
$Pfad.Size = New-Object System.Drawing.Size(120,22)
$Pfad.Text = "Pfad auswählen"
$Pfad.TabIndex = 5
$Pfad.BackColor = "white"
$Pfad.Add_Click()
$GroupBoxExport.Controls.Add($Pfad)
# Export-Button
$Export = New-Object System.Windows.Forms.Button
$Export.Location = New-Object System.Drawing.Size(360,60)
$Export.Size = New-Object System.Drawing.Size(80,22)
$Export.Text = "Export"
$Export.TabIndex = 5
$Export.BackColor = "white"
$Export.Add_Click()
$GroupBoxExport.Controls.Add($Export)
#Exportstatusanzeigen lassen
$ExportStatusInfo = New-Object System.Windows.Forms.Label
$ExportStatusInfo.Location = New-Object System.Drawing.Size(7,90)
$ExportStatusInfo.Size =New-Object System.Drawing.Size(450,20)
$ExportStatusInfo.Text = ""
$GroupBoxExport.Controls.Add($ExportStatusInfo)
#Forstschrittsanzeige export
$ExportProgressBar = New-Object System.Windows.Forms.ProgressBar
$ExportProgressBar.Location = New-Object System.Drawing.Size(10,110)
$ExportProgressBar.Size = New-Object System.Drawing.Size(430,20)
$ExportProgressBar.MarqueeAnimationSpeed = 30
$ExportProgressBar.Visible = $true
$GroupBoxExport.Controls.Add($ExportProgressBar)
# Fenster anzeigen lassen
$Fenster1.Add_Shown()
[System.Windows.Forms.Application]::EnableVisualStyles()
#[System.Windows.Forms.Application]::Run($ExportProgressBar)
[void] $Fenster1.ShowDialog()
[…] Mailbox-Exporter […]