3

I'm trying to filter about 2000 automated alerts in an outlook sub-folder.

I need to do the following series of steps:

  1. Parse sub-folder Account Alert Lockouts
  2. Search for a specific phrase that has a variable username
  3. Dump out that whole phrase with the variable username into csv

Example Phrase

Account Name:       jdoe

I have all of the required emails in a sub-folder, I just need to analyze them.

I've gotten my code to work in the Inbox, but it doesn't cover the sub-folder.

Add-Type -Assembly "Microsoft.Office.Interop.Outlook"
$Outlook = New-Object -ComObject Outlook.Application
$namespace = $Outlook.GetNameSpace("MAPI")

$inbox = $namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)    

$RE = [RegEx]'(?sm)Account Name\s*:\s*(?<AccName>.*?)$.*'

$DebugPreference = 'Continue'

$Data = foreach ($item in $inbox.items) {
    if ($item.body -match $RE) {
        Write-Host "ding "
        [PSCustomObject]@{ AccName = $Matches.AccName }
    }
}

$Data 
$Data | Export-CSv '.\data.csv' -NoTypeInformation

1 Answer 1

2

Per the documentation for NameSpace.GetDefaultFolder:

To return a specific non-default folder, use the Folders collection.

And the documentation for the Folders collection referenced above:

Use Folders (index), where index is the name or index number, to return a single Folder object. Folder names are case-sensitive.

You should be able to add this:

$subfolder = $inbox.Folders('Account Alert Lockouts')

and change your foreach to iterate over $subfolder.

Sign up to request clarification or add additional context in comments.

2 Comments

Ugh. I spend a couple hours researching other questions and yours is so stupid simple. I'm a big dummy. Yeah, it worked immediately just as you said. Thank you.
Haha I've been there plenty of times. Glad I could help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.