INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Export Mailboxes from Given Server or Database to Shared Path

Export Mailboxes from Given Server or Database to Shared Path

Export Mailboxes from Given Server or Database to Shared Path

(OP)
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.

$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."
 

RE: Export Mailboxes from Given Server or Database to Shared Path

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close