Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Script against outlook mail box is selecting old data

$
0
0

Hi there,

I am into this project wherein emails pushed into a folder has to be cross checked whether it arrives.

So, to meet this end, I used a powershell script to connect to the mail folder and collect the data.

Add-Type $class -ReferencedAssemblies Microsoft.Office.Interop.Outlook
$class = @"
using Microsoft.Office.Interop.Outlook;public class MyOL
{
    public MAPIFolder GetInbox(string userName)
    {
        Application oOutlook = new Application();
        NameSpace oNs = oOutlook.GetNamespace("MAPI");
        Recipient oRep = oNs.CreateRecipient(userName);
        MAPIFolder inbox = oNs.GetSharedDefaultFolder(oRep, OlDefaultFolders.olFolderInbox);
        return inbox;
    }
}
"@
Add-Type $class -ReferencedAssemblies Microsoft.Office.Interop.Outlook

$MyOL = New-Object MyOL
$olInbox = $MyOL.GetInbox("mailbox")

$olInbox.items | Select-Object -Property Subject, ReceivedTime, Importance, SenderName

but this code is collecting only a week old data! I did try a bit of looking around and found that this can be related to the indexes in the mailbox. So, I have tried disabling that as well but in vain.

Please can someone help me on this.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>