Retrieve mail from an Outlook Inbox Subfolder

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Daniël Daniël 1 year, 11 months ago.

  • Author
    Posts
  • #24432
    Profile photo of I Am Sir Ask Alot
    I Am Sir Ask Alot
    Participant

    I am trying to retrieve data from an Inbox subfolder and I am having a brain block.

    Can someone please help me with this?

    The folder is just one level below my Outlook Inbox and I need to parse information from the email items in this subfolder. Basically, the subfolder's name is "Microsoft Project and Visio Installs Inventory Notices" and I would like to have a script that can read each mail item and output the info like this:

    XX number of Visio Pro Installs
    XX number of Visio Standard Installs
    XX number of Project Pro Installs
    XX number of Project Standard Installs

    For some reason I just cannot get my head wrapped around it.

    This is what I have so far, but I am needing to tweak this a bit to get the results I desire, such as setting it to read from the "Microsoft Project and Visio Installs Inventory Notices" subfolder.

    $GetMailItems = @(
        $OutlookInbox = 6
        $Outlook = New-Object -Com Outlook.Application;
        $NameSpace = $Outlook.GetNameSpace("MAPI");
        $Inbox = $NameSpace.GetDefaultFolder($OutlookInbox)
    
        $Inbox.Items | ForEach {
            If ($_.Body -match "Project|Visio" -and $_.Body -notmatch "MUI|Service Pack|Update|Viewer|Vision") 
            {
                Write-Output $_.Body
            }})
    
    $GetMailItems

    Thanks

  • #24519
    Profile photo of Daniël
    Daniël
    Participant

    You can specify the subfolder to read from before the ForEach statement:

    ($Inbox.Folders | ?{$_.Name -eq 'Subfolder'}).Items
    

    Hope this helps.

You must be logged in to reply to this topic.