How to automate movement of messages between folders in mailbox, Exchange 2010
I had wrong configured content filter on Exchange 2010.
So I have a lot of messages in Junk Mail folders on more than 400+ mailboxes.
So I need to move these messages into Inbox folder. I didn't find how to automate such operation. I found such problem only in thread:
http://social.technet.microsoft.com/Forums/en-US/exchangesvradmin/thread/43582019-caaf-4011-8f0d-68871d46ea12
Its not resolved
And I have one idea: move messages from "Junk mail" using "export-mailbox" cmdlet to some temp mailbox, then move back to folder "Inbox". Repeat this action on every mailbox.
Maybe there is easiest way? Any suggestions?
October 18th, 2010 8:27am
Glen Scales posted a script a while back using the EWS Managed API that could should be a good starting point if you want to go that route:
http://gsexdev.blogspot.com/2009/10/moving-items-into-their-own-folder-by.html[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
October 18th, 2010 8:54am
Thanks a lot. I rewrote the script and it works great for one mailbox, but I was confronted with difficulties when was trying to apply it for each mailbox.
I have 3 variants of the script. There is one of them:
$StartDate = [system.DateTime]::Today.AddDays(-30)
$EndDate = [system.DateTime]::Today
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFile($dllpath)
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)
$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + ">"
$aceuser = [ADSI]$sidbind
$service.AutodiscoverUrl($aceuser.mail.ToString())
write-host "Moving messages from Junk Mail to Inbox"
ForEach ($mbx in Get-Mailbox -Database Shops) {
$MailboxName = $mbx.PrimarySmtpAddress.ToString()
$MailboxName
$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)
$InboxFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
$folderid2 = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::JunkEmail,$MailboxName)
$JunkEmailFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid2)
$Sfgt = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsGreaterThan([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived, $StartDate)
$Sflt = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsLessThan([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived, $EndDate)
$sfCollection = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+SearchFilterCollection([Microsoft.Exchange.WebServices.Data.LogicalOperator]::And);
$sfCollection.add($Sfgt)
$sfCollection.add($Sflt)
$view = new-object Microsoft.Exchange.WebServices.Data.ItemView(2000)
$frFolderResult = $JunkEmailFolder.FindItems($sfCollection,$view)
foreach ($miMailItems in $frFolderResult.Items){
"Moving " + $miMailItems.Subject.ToString()
[VOID]$miMailItems.Move("Inbox")
}
}
But I always have errors:
Exception calling "Bind" with "2" argument(s): "The specified object was not found in the store."
At C:\psscript\move_junk_to_inbox.ps1:15 char:66
+ $InboxFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind <<<< ($service,$folderid)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Exception calling "Bind" with "2" argument(s): "The specified folder could not be found in the store."
At C:\psscript\move_junk_to_inbox.ps1:17 char:70
+ $JunkEmailFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind <<<< ($service,$folderid2)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
MCP
October 21st, 2010 3:33am