I'm trying to filter about 2000 automated alerts in an outlook sub-folder.
I need to do the following series of steps:
- Parse sub-folder
Account Alert Lockouts - Search for a specific phrase that has a variable username
- 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