【发布时间】:2011-10-11 15:59:22
【问题描述】:
我有一个小型 powershell 脚本,它使用 Outlook 互操作将某些邮件从收件箱移动到其他文件夹。基本的移动操作使用以下代码完成:
[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 条消息。
以前有人观察过这种行为吗?我有什么明显的遗漏吗?
【问题讨论】:
-
我已经完成了各种 SenderName 和 $message.count 匹配 Outlook 上的计数(也与来自发件人的 567 封邮件)
标签: powershell outlook office-interop outlook-2007 mapi