QuickBlog: PowerShell – Extracting emails from your Outlook Inbox

This is a quick-to-the-point sample of a PowerShell 5 liner that will extract email information from your Outlook Inbox.  I my current position I have to verify, via emails,  that the SQL Server scheduled tasks have successfully completed.  Also I need to report any failures.  So, I decided to use PowerShell to filter out all the email coming from the SQL Server.

If you all wondered… I got this concept from a VBscript code I found on the internet: (here’s the link)

http://blogs.msdn.com/deva/archive/2008/12/02/outlook-programming-looping-individual-mails-inside-the-inbox.aspx

Also, there’s a caveat with Outlook.  There’s a security box that will come up:

And here’s how to disable it,  from the main menu go to "Tools | Macro | Security | Programmatic Access" then "No Security check…".  

Here’s 5 line… the final result: 

   $GetOutlook = New-Object -com "Outlook.Application";

   $olName = $GetOutlook.GetNamespace("MAPI")

   $olxFolder = $olName.GetDefaultFolder(‘olFolderInbox’)

   $olxItem = $olxFolder.items

   $olxItem | ? {$_.to -eq "SQLAdminGroup"} | select -first 25 SentOn, SenderName, Subject | FL

In this scenario, I’m using the “To” property to filter the email and then I grab the first 25 email because I have about less than 30 jobs running.

Now, keep in mind, that you can save results to an output file and/or send it to a HTML formatted file.

Just to show you this scripting technology is powerful.

Advertisements

About maxt2posh

I’m from Puerto Rico, have been working with computers since 1979. Throughout many years, I have worked with SQL Server Technologies, provided support to Windows Servers/Client machines, Microsoft Virtualization Technologies, and build some Visual Studio solutions. I’m a Microsoft PowerShell MVP since 2009 and MVP SAPIEN Technologies since 2010. I speak in most of the SQLSaturday, IT Pro and .NET camps events around the Florida’s State. Also founder of the Florida PowerShell User Group which meeting every 3rd Tuesday evening of the month.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s