Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can Powershell parse email?

1,717 views
Skip to first unread message

akcorr

unread,
Mar 26, 2008, 11:37:04 AM3/26/08
to
Is there a way for powershell to read an inbox and look for a specific string
in the subject or body?

Keith Hill [MVP]

unread,
Mar 26, 2008, 11:52:40 AM3/26/08
to
"akcorr" <akc...@discussions.microsoft.com> wrote in message
news:CE0C6455-6881-4302...@microsoft.com...

> Is there a way for powershell to read an inbox and look for a specific
> string
> in the subject or body?

If you are using Outlook then you can use Outlook COM Automation. Have a
look at this KB article:

http://support.microsoft.com/default.aspx/kb/310244

That C# code should translate to PowerShell script pretty easily.

--
Keith

Marco Shaw [MVP]

unread,
Mar 26, 2008, 12:06:21 PM3/26/08
to
akcorr wrote:
> Is there a way for powershell to read an inbox and look for a specific string
> in the subject or body?

Now, if you're dealing with an IMAP mailbox, you can also check out
NetCmdlets:
http://www.nsoftware.com/powershell

They have a get-imap cmdlet that can retrieve messages, and then you can
search through them after...

There's also a get-pop (or get-pop3 cmdlet). Don't try to use
PowerShell to read the Inbox from Outlook Express or Live Mail directly
from the local inbox file! It can't decode it, as far as I know.

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com

Shay Levi

unread,
Mar 26, 2008, 12:11:44 PM3/26/08
to

If your email client is outlook:


$olFolderInbox = 6
$outlook = new-object -com outlook.application;
$ns = $outlook.GetNameSpace("MAPI");
$inbox = $ns.GetDefaultFolder($olFolderInbox)


$inbox.items | foreach {
if($_.subject -match "something") {...}
if($_.body -match "something") {...}
}

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com

kelly goff

unread,
Mar 26, 2008, 2:43:17 PM3/26/08
to
akcorr wrote:
> Is there a way for powershell to read an inbox and look for a specific string
> in the subject or body?
Yes, it can. But how you do it depends on whether you are running the
script on the server or a client.

Which do you need?

Kelly Goff

Clarkent 83

unread,
Oct 11, 2010, 12:57:49 PM10/11/10
to
I'm searching a way to parse an email for a specific word in a user mailbox but server side.

tried to use the com commands but it is only being used in outlook client side :(

Thanks

> On Wednesday, March 26, 2008 11:37 AM akcor wrote:

> Is there a way for powershell to read an inbox and look for a specific string
> in the subject or body?


>> On Wednesday, March 26, 2008 11:52 AM Keith Hill [MVP] wrote:

>> "akcorr" <akc...@discussions.microsoft.com> wrote in message
>> news:CE0C6455-6881-4302...@microsoft.com...
>>

>> If you are using Outlook then you can use Outlook COM Automation. Have a
>> look at this KB article:
>>
>> http://support.microsoft.com/default.aspx/kb/310244
>>
>> That C# code should translate to PowerShell script pretty easily.
>>
>> --
>> Keith


>>> On Wednesday, March 26, 2008 12:06 PM Marco Shaw [MVP] wrote:

>>> akcorr wrote:
>>>
>>> Now, if you're dealing with an IMAP mailbox, you can also check out
>>> NetCmdlets:
>>> http://www.nsoftware.com/powershell
>>>
>>> They have a get-imap cmdlet that can retrieve messages, and then you can
>>> search through them after...
>>>
>>> There's also a get-pop (or get-pop3 cmdlet). Don't try to use
>>> PowerShell to read the Inbox from Outlook Express or Live Mail directly
>>> from the local inbox file! It can't decode it, as far as I know.
>>>
>>> Marco
>>>
>>> --
>>> Microsoft MVP - Windows PowerShell
>>> http://www.microsoft.com/mvp
>>>
>>> PowerGadgets MVP
>>> http://www.powergadgets.com/mvp
>>>
>>> Blog:
>>> http://marcoshaw.blogspot.com


>>>> On Wednesday, March 26, 2008 2:43 PM kelly goff wrote:

>>>> akcorr wrote:
>>>> Yes, it can. But how you do it depends on whether you are running the
>>>> script on the server or a client.
>>>>
>>>> Which do you need?
>>>>
>>>> Kelly Goff


>>>>> On Friday, March 28, 2008 6:15 AM Shay Levi wrote:

>>>>> If your email client is outlook:
>>>>>
>>>>>
>>>>> $olFolderInbox = 6
>>>>> $outlook = new-object -com outlook.application;
>>>>> $ns = $outlook.GetNameSpace("MAPI");
>>>>> $inbox = $ns.GetDefaultFolder($olFolderInbox)
>>>>>
>>>>>
>>>>> $inbox.items | foreach {
>>>>> if($_.subject -match "something") {...}
>>>>> if($_.body -match "something") {...}
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> -----
>>>>> Shay Levi
>>>>> $cript Fanatic
>>>>> http://scriptolog.blogspot.com


>>>>> Submitted via EggHeadCafe - Software Developer Portal of Choice
>>>>> Book Review: Google Analytics
>>>>> http://www.eggheadcafe.com/tutorials/aspnet/a855a620-50a8-487c-9fac-b85f8fda2442/book-review-google-analytics.aspx

0 new messages