# Retrieve mail from an Outlook Inbox Subfolder

**URL:** <https://forums.powershell.org/t/retrieve-mail-from-an-outlook-inbox-subfolder/4061>\
**Category:** PowerShell Help\
**Created:** [April 17, 2015, 9:51am UTC](https://forums.powershell.org/t/retrieve-mail-from-an-outlook-inbox-subfolder/4061 "2015-04-17T09:51:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [April 17, 2015, 9:51am UTC](https://forums.powershell.org/t/retrieve-mail-from-an-outlook-inbox-subfolder/4061/1 "2015-04-17T09:51:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daniel](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@daniel](https://forums.powershell.org/u/daniel)\
**Post date:** [April 21, 2015, 5:53am UTC](https://forums.powershell.org/t/retrieve-mail-from-an-outlook-inbox-subfolder/4061/2 "2015-04-21T05:53:45Z")

</div>

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

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

Hope this helps.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:45pm UTC](https://forums.powershell.org/t/retrieve-mail-from-an-outlook-inbox-subfolder/4061/3 "2024-05-16T20:45:27Z")

</div>

Closed on May 16, 2024, 8:45pm UTC


