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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export Mailboxes from Given Server or Database to Shared Path

Status
Not open for further replies.

paramjotsingh

Technical User
Sep 22, 2015
13
0
0
CA
I am new to programming, actually I am Cisco guy and having zero knowledge for coding. Anyhow I want to accomplish a task through PowerShell script. Following is script working but not as per I want. I following tasks:

1) Script has get all the mailboxes from specified Server or Database.
2) It has to export all the mailboxes of prior month from that date it is run. For e.g. If run the script on Dec. 10' 2015, then it has export all the mailboxes from Nov. 10 to Dec. 9' 2015. Next time if I run this script on Dec. 30, it has to export mailboxes from Nov 30 to Dec. 29' 2015.

But my script takes the mailboxes from whole Exchange database and export it. I used the content filter as well but it always exports whole database, it ignores the "month" filtration. Please advise how can i correct this script. I searched a Google lot but ended up by exporting manual specific date content filter.

[pre]
$Export = Get-Mailbox
$endDate = Get-Date
$startDate = $endDate.AddMonths(-1)
$month = "{0:D2}" -f [int]$startDate.Month

$endDate = $endDate.ToShortDateString()
$startDate = $startDate.ToShortDateString()

Write-Host -NoNewline "Exporting items between $startDate and $endDate..."

$Export|%{$_|New-MailboxExportRequest -ContentFilter {(Received -ge $startDate) -and (Received -lt $endDate)} -FilePath "\\FileServer\EmailBackups\ExportTest\MonthTest\$($_.alias).pst"}

Write-Host "Done."
[/pre]
 
paramjotsingh,
Where are you filtering the database?

I think you need to add something like this to the beginning.
Also, you may want to add some error checking, like making sure the selection is an integer and is within the range of valid choices.

Code:
$databases = Get-MailboxDatabase
$looper = 0
foreach ($database in $databases)
	{
	 Write-Host "$looper.  " -nonewline
	 Write-Host $database.name
	 $looper ++
	}
Write-Host ""
$db_selection = Read-Host "Enter the number of the database you want to export"
$Export = Get-Mailbox -Database ($databases[$db_selection].name)

## The rest of your code goes below
$endDate = Get-Date
$startDate = $endDate.AddMonths(-1)
$month = "{0:D2}" -f [int]$startDate.Month

$endDate = $endDate.ToShortDateString()
$startDate = $startDate.ToShortDateString()

Write-Host -NoNewline "Exporting items between $startDate and $endDate..."

$Export|%{$_|New-MailboxExportRequest -ContentFilter {(Received -ge $startDate) -and (Received -lt $endDate)} -FilePath "\\FileServer\EmailBackups\ExportTest\MonthTest\$($_.alias).pst"}

Write-Host "Done."


Light travels faster than sound. That's why some people appear bright until you hear them speak.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top