使用PowerShell移动具有特定主题的未读Outlook邮件

时间:2018-08-26 18:55:09

标签: powershell-v5.0 outlook-2016

我一直在尝试创建PowerShell脚本,该脚本将将具有特定主题的未读Outlook邮件移动到另一个文件夹。

我尝试过的完整代码可在[https://pastebin.com/ZLQcx3tU][1]

中找到

我尝试了2种不同的方法。

方法1

   #This Piece of Code only moves Certain Mails
    #Explanation: - If there are 5 mails with the Subject containing **Error** only 3 get moved and the rest stay in the Inbox
    $oInbox.Items.Restrict('[UnRead] =   True') |
    ForEach-Object {
    If ($_.subject -Like "*$sSearchSubject*") {
    $_.Move($oTargetFolder)
    }
    }

方法2

#This piece does not work though I know this is the way the coding should be done
#Explanation: - If there are 5 mails with the Subject containing **Error** NONE get moved.

#I bet I am doing something SILLY but not able to figure it out
 For($iMailCount=($oInbox.count-1);$iMailCount -ge 0;$iMailCount--)
{
If ($_.subject -Like "*$sSearchSubject*")
{
$($oInbox)[$iMailCount].move($oTargetFolder)
}
 }

我需要Powershell大脑来指导我这段代码。

致谢

0 个答案:

没有答案