Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export a Single Mailbox

PowerShell

Export a Single Mailbox

by  markdmac  Posted    (Edited  )
Code:
[green]
#==========================================================================
#
# Script: ExportMailbox.ps1
#
# AUTHOR:  Mark D. MacLachlan, The Spider's Parlor 
# Date: 01/14/2014 
#
#    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
#    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
#    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
#    PARTICULAR PURPOSE.
#
#    IN NO EVENT SHALL THE SPIDERS PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
#    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
#    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
#    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
#    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
#    OF THIS CODE OR INFORMATION.
#
#
# COMMENT: 
#   
#
#==========================================================================

#Get the alias name[/green]
$Alias = Read-Host "Enter mailbox name"
[green]
#Show the user the mailbox size[/green]
$MailboxSize = Get-MailboxStatistics -Identity $Alias | where {$_.ObjectClass ûeq ôMailboxö} | Sort-Object TotalItemSize ûDescending | ft @{label=öUserö;expression={$_.DisplayName}},@{label=öTotal Size (GB)ö;expression={$_.TotalItemSize.Value.ToGB()}},@{label=öItemsö;expression={$_.ItemCount}} -auto
Write-Host $MailboxSize
[green]
#Get the path to create the PST in[/green]
$PSTPath = Read-Host "Enter PST Path (MUST BE A UNC PATH)"
[green]
#Get the  PST name[/green]
$PSTName = Read-Host "Enter PST Name"
[green]
#Check if PST ends in .PST, add it if not.[/green]
If($PSTName.Length -lt 4)
{$PSTName = $PSTName + ".pst"}
$EndPST = $PSTName.substring($PSTName.length - 4, 4)
If($EndPST -eq ".pst")
{$PSTName = $PSTName}
Else
{$PSTName = $PSTName + ".pst"}
[green]
#Check if the PSTPath ends in a slash or not, add it if needed and join with PST name[/green]
$EndSring = $PSTPath.substring($PSTPath.length - 1, 1)
If($EndString -eq "\")
{$FullPSTPath = $PSTPath + $PSTName}
Else
{$FullPSTPath = $PSTPath + "\" + $PSTName}

[green]
#Check how many bad items are allowed[/green]
$BadAllowed = Read-Host "Enter number of allowed bad items -recommended 150"
[green]
#Specify if we need a date range to export of not.[/green]
$SelectDate = Read-Host "Select a date range? Y or N")

[green]
#Now execute the export request[/green]
If($SelectDate -eq "y")
{[green]
#Get date ranges[/green]
$StartRange = Read-Host "Enter Start Date  MM/DD/YYYY"
$EndRange = Read-Host "Enter End Date  MM/DD/YYYY"
[green]#Make it so[/green]
New-MailboxExportRequest -ContentFilter {(Received -lt "$EndRange") -and (Received -gt "StartRange")} -Mailbox $Alias -FilePath "$FullPSTPath"-BadItemLimit $BadAllowed -AcceptLargeDataLoss
}
Else
{[green]
#Make it so[/green]
New-MailboxExportRequest -Mailbox $Alias -FilePath "$FullPSTPath"-BadItemLimit $BadAllowed -AcceptLargeDataLoss
}
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top