How can I get a count of emails using a specific parameter such as size or age?
I would like to do somthing like this: Get-mailboxfolderstatistics -idtentity user -folderscope inbox | where {$_.messagesize -gt "$x"} or Get-mailboxfolderstatistics -idtentity user -folderscope inbox | where {$_.messagecreatedate -lt "08/1/2010"} Any Ideas?
April 29th, 2011 12:29pm

The Get-MailboxFolderStatistics cmdlet is used to retrieve information about the folders in a specified mailbox. It does not read each message to gather the size and age information you seek. You would likely have to write something more complex using Exchange Web Services. What are you actually trying to accomplish? Have you explored the use of retention tags/policies? Mike Crowley | MVP My Blog -- Planet Technologies
Free Windows Admin Tool Kit Click here and download it now
April 29th, 2011 4:03pm

I am writing a script to clean up a HUGE mailbox. Right now my script will go back one month at a time and export that months emails to a pst named after that month and year. I want it to stop once it gets to a month that has no emails. I was hoping to be able to do something that could check a mailbox to see if there were any messages and if the count was zero for that month stop running the script. I need to hold onto the emails for data archiving policies. TIA, James
April 29th, 2011 4:55pm

Here's what I've got so far. Warning, I am a powershell noob: ## Go back one month at a time looking for messages, if there are any, export to PST. $startDate = Get-date $day = $startDate.day - 1 $startDate = $startDate.adddays(-$day) function setdate { ## Set start date as the first day of the month TWO MONTHS BACK. $startDate = $startDate.addmonths(-2) $startDateStr = $startDate.toshortdatestring() $month = $startDate.month $year = $startDate.year $numDays = [datetime]::DaysInMonth($year,$month) - 1 $endDate = $startDate.AddDays($numDays) $endDateStr = $endDate.toshortdatestring() $PSTFileName = [string]$month + '-' + [string]$year + '.pst' Write-Host 'From ' $startDateStr ' To ' $endDateStr $t = read-host "go?" } setdate while ($startdate -gt "08/01/2010") { Export-Mailbox -Identity "User" -PSTFolderPath \\server\folder -IncludeFolders '\Inbox' -StartDate $startDateStr -EndDate $endDateStr -DeleteContent -Confirm $t = read-host "go?" setdate }
Free Windows Admin Tool Kit Click here and download it now
April 29th, 2011 5:03pm

Here's what I've got so far. Warning, I am a powershell noob: ## Clean up Exchange mailbox. ## This will remove messages that are older than three months and store them on the file server. ## Go back one month at a time looking for messages, if there are any, export to PST. ##Set start date to the first of the month. $startDate = Get-date $day = $startDate.day - 1 $startDate = $startDate.adddays(-$day) ## Set start date as the first day of the month TWO MONTHS BACK. $startDate = $startDate.addmonths(-2) ##Set the end date to the last day of the month and create strings to pass to the export command. $startDateStr = $startDate.toshortdatestring() $month = $startDate.month $year = $startDate.year $numDays = [datetime]::DaysInMonth($year,$month) - 1 $endDate = $startDate.AddDays($numDays) $endDateStr = $endDate.toshortdatestring() ## Name the output file. $PSTFileName = [string]$month + '-' + [string]$year + '.pst' while ($startdate -gt "08/01/2010") { Write-Host 'Exporting emails from ' $startDateStr ' To ' $endDateStr Export-Mailbox -Identity "User" -PSTFolderPath \\server\folder\$pstFileName -IncludeFolders '\Inbox\Processed' -StartDate $startDateStr -EndDate $endDateStr -DeleteContent -Confirm:$false $startDate = $startDate.addmonths(-1) $startDateStr = $startDate.toshortdatestring() $month = $startDate.month $year = $startDate.year $numDays = [datetime]::DaysInMonth($year,$month) - 1 $endDate = $startDate.AddDays($numDays) $endDateStr = $endDate.toshortdatestring() $PSTFileName = [string]$month + '-' + [string]$year + '.pst' }
April 30th, 2011 12:01am

Hi Jimmy, Based on my research, there is no better way to get a count of emails using a specific parameter such as size or age. Please ask the question on our Development forum, maybe somebody there can help on your issue: Exchange Development forum http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/threads Thanks, Evan Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
May 4th, 2011 11:02am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics