0
我有一个小PowerShell脚本,它使用Outlook互操作将某些邮件从收件箱移动到其他文件夹。基本的移动操作使用下面的代码完成:展望Items.Restrict不返回所有邮件
[Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.Outlook") | Out-Null
$olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$inbox = $namespace.getDefaultFolder($olFolders::olFolderInbox)
$filter = "[SenderName] = 'Dummy Sender'"
$messages = $inbox.items.Restrict($filter)
$messages | % {
Write-Host "`t$($_.Subject)"
[void]$_.Move($destination) | Out-Null
}
我注意到的问题是,items.Restrict
没有返回所有匹配的消息。每次运行脚本时,我都会收到3到20条消息。
有没有人观察过此行为?有什么明显的我失踪了?
我已经完成varius SenderName和$ message.count匹配计数前景(还有来自发件人的567封邮件) –