paramjotsingh
Technical User
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 = "{02}" -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]
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 = "{02}" -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]