usersubuser
usersubuser

Reputation: 117

Update Outlook inbox folder

I would like to update (sync) the inbox folder (send/receive) before running this PowerShell script that gets the e-mails, but I don't know how. Is there a way to do this from powershell?

$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 

Upvotes: 1

Views: 1807

Answers (1)

4c74356b41
4c74356b41

Reputation: 72151

This is how you do that:

$mapi.SendAndReceive($false)

Also, for me I needed to use the Logon method before the SendAndReceive:

$mapi.logon()

Check the link for more reference.

Upvotes: 1

Related Questions