2016-11-13 162 views
0

我想在運行此PowerShell腳本獲取電子郵件之前更新(同步)收件箱文件夾(發送/接收),但我不知道如何。有沒有辦法從PowerShell這樣做?更新Outlook收件箱文件夾

$matchString= "[email protected]"; 
$olFolderInbox = 6 
$outlook = New-Object -COM Outlook.Application; 
$mapi = $outlook.GetNameSpace("MAPI"); 
$inbox = $mapi.GetDefaultFolder($olFolderInbox) 

$inbox.Items | where { $_.SenderEmailAddress -match $matchString } | 
    Select SenderEmailAddress,to,subject | 
    Format-Table -AutoSize 
+0

您使用的是哪個版本的Outlook?因爲即使我能夠運行$ mapi.SendAndReceive($ false) –

回答

0

這是如何做到這一點:

$mapi.SendAndReceive($false)

而且,對我來說,我需要的SendAndReceive之前使用的登錄方法:

$mapi.logon()

Check the link for more reference

+0

我得到一個錯誤:「方法調用失敗,因爲[System .__ ComObject]不包含名爲'SendAndReceive'的方法。」 – usersubuser

+0

你使用的是什麼版本? – 4c74356b41

+0

登錄後有效,謝謝 – usersubuser

相關問題