更新 Outlook 收件箱文件夹

Update Outlook inbox folder

我想在 运行 此获取电子邮件的 PowerShell 脚本之前更新(同步)收件箱文件夹 (send/receive),但我不知道如何操作。有没有办法从 powershell 做到这一点?

$matchString= "support@blabla.com";
$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 

这就是你的做法:

$mapi.SendAndReceive($false)

此外,对我来说,我需要在 SendAndReceive 之前使用 Logon 方法:

$mapi.logon()

Check the link for more reference.