Перемещение непрочитанных писем Outlook с конкретными темами с помощью PowerShell - PullRequest
0 голосов
/ 26 августа 2018

Я пытался создать сценарий 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 для руководства по этому коду.

С уважением

...