2016-11-13 73 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

相关问题