{"id":13831,"date":"2011-05-25T00:01:00","date_gmt":"2011-05-25T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/05\/25\/use-powershell-to-data-mine-your-outlook-sent-items\/"},"modified":"2011-05-25T00:01:00","modified_gmt":"2011-05-25T00:01:00","slug":"use-powershell-to-data-mine-your-outlook-sent-items","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-data-mine-your-outlook-sent-items\/","title":{"rendered":"Use PowerShell to Data Mine Your Outlook Sent Items"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, teaches you how to use Windows PowerShell to data mine your Sent Items folder in Microsoft Outlook.<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" \/> Hey, Scripting Guy! I was wondering if I would use Windows PowerShell to process my Sent Items in Outlook. I mean, I think there is some interesting data I could obtain if I could find an easy way to work with the information. Is this something that can be done with Outlook and with Windows PowerShell?<\/p>\n<p>&mdash;SH<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" \/> Hello SH, <\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. If you use Microsoft Outlook nearly as much as I do, you have an extensive data repository in your Sent Items folder. For example, every Live Meeting I schedule with various user groups comes through Outlook at some time or another. If I want to know how many Live Meetings I participate in during a year, I can search my Outlook Sent Items. <\/p>\n<p>Because the Sent Items folder contains so much data, and because I may want to parse the data in many different fashions, it is a perfect candidate to turn into a reusable Windows PowerShell function that returns an object. <\/p>\n<p>The actual code that retrieves the Sent Items is about eight lines long. The remainder of the code is comment-based Help. I am not going to discuss the comment-based Help. However, I will show you a couple of things. After I have loaded the function into memory (in the Windows PowerShell ISE, I run the script file that contains the function and it loads the function for me), I can use the <b>Get-Help<\/b> cmdlet to obtain information about the function. The basic command is shown here:<\/p>\n<blockquote>\n<p><span style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Get-Help Get-OutlookSentItems<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>The command and its associated output are shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3301.HSG-5-25-11-1_1A745564.jpg\"><img decoding=\"async\" height=\"469\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6507.HSG-5-25-11-1_thumb_79ED15B1.jpg\" alt=\"Image of command output\" border=\"0\" title=\"Image of command output\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" \/><\/a><\/p>\n<p>If I need to see the complete Help information, I use the <b>Full<\/b> switch with <b>Get-Help<\/b>. This command is shown here:<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Get-Help &ndash;full Get-OutlookSentItems<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>When I have read through the Help and I understand how the function works, I may need to be reminded of helpful syntax. To do this, I use the <b>Examples<\/b><i> <\/i>switch with the function. This command is shown here:<\/p>\n<blockquote>\n<p><span style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Get-Help &ndash;examples Get-OutlookSentItems<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>The main working code in the <b>Get-OutlookSentItems<\/b> function loads the interop assembly, and creates the <a target=\"_blank\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff861868.aspx\">olDefaultFolders enumeration type<\/a>. Next, I create an instance of the <a target=\"_blank\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff863377.aspx\">Outlook.Application object<\/a>, and connect to the MAPI namespace. These are common steps when working with Microsoft Outlook. This portion of the code is shown here: <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Add-type -assembly &#8220;Microsoft.Office.Interop.Outlook&#8221; | out-null<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>$olFolders = &#8220;Microsoft.Office.Interop.Outlook.olDefaultFolders&#8221; -as [type] <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>$outlook = new-object -comobject outlook.application<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>$namespace = $outlook.GetNameSpace(&#8220;MAPI&#8221;)<\/span><\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>After I have created the objects, enumerations, and interop assemblies, and connected to the MAPI namespace, it is time to call the <b>GetDefaultFolder<\/b> method and connect to the sent mail folder. I store the returned folder object in the <b>$folder<\/b> variable. <\/p>\n<blockquote>\n<p><span style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$folder = $namespace.getDefaultFolder($olFolders::olFolderSentMail)<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>Now I call the <b>items<\/b> method from the <b>folder<\/b> object, and I choose the four properties with which I want to work. The <b>Select-Object<\/b> cmdlet creates a custom object for me and returns a custom object for each mail item in the folder. This portion of the script is shown here:<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$folder.items | <\/span><\/span><\/span><\/p>\n<p><span style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>Select-Object -Property Subject, SentOn, Importance, To<\/span><\/span><\/span><\/span><\/p><\/blockquote>\n<p>The complete <b>Get-OutlookSentItems<\/b> function is shown here. (I know that copying and pasting from the blog format can often be a challenge&mdash;for this reason I uploaded the complete <a target=\"_blank\" href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/a38c361e-667e-4c09-835c-a53cb874faac\">Get-OUtlookSentItems function<\/a> to the Scripting Guys Script Repository).<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Function Get-OutlookSentItems<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">{<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp; <\/span><\/span><span>&lt;#<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Synopsis<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>This function returns sent items from default Outlook profile<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Description<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>This function returns sent items from default Outlook profile. It<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>uses the Outlook interop assembly to use the olFolderSentMail enumeration.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>It creates a custom object consisting of Subject, SentOn, Importance, To<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>for each sent item. <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>*** Important *** depending on the size of your sent items this function<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>may take several minutes to gather your sent items. If you anticipate <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>doing multiple analysis of the data, you should consider storing the <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>results into a variable, and using that. <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Example<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Get-OutlookSentItems | <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>where { $_.SentOn -gt [datetime]&#8221;5\/5\/11&#8243; -AND $_.SentOn -lt `<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>[datetime]&#8221;5\/10\/11&#8243; } | sort importance <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Displays Subject, SentOn, Importance, To for all sent items that were sent<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>between 5\/5\/11 and 5\/10\/11 and sorts by importance of the email.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Example<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Get-OutlookSentItems | Group-Object -Property To | sort-Object Count <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Displays Count, To and grouping information for all sent items. The most<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>frequently used contacts appear at bottom of list. <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Example<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>$sentItems = Get-OutlookSentItems<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Stores Outlook sent items into the $sentItems variable for further<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>&#8220;offline&#8221; processing.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Example<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>($sentItems | Measure-Object).count<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Displays the number of messages in Sent Items<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Example<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>$sentItems | where { $_.subject -match &#8216;2011 Scripting Games&#8217; } | <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span>sort SentOn -Descending | select subject, senton -last 5 <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Uses $sentItems variable (previously created) and searches subject field<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>for the string &#8216;2011 Scripting Games&#8217; it then sorts by the date sent.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>This sort is descending which puts the oldest messages at bottom of list.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>The Select-Object cmdlet is then used to choose only the subject and sentOn<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>properties and then only the last five messages are displayed. These last<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>five messages are the five oldest messages that meet the string. <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Notes<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>NAME:<span>&nbsp; <\/span>Get-OutlookSentItems<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>AUTHOR: ed wilson, msft<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>LASTEDIT: 05\/10\/2011 08:36:42<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>KEYWORDS: Microsoft Outlook, Office<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>HSG: HSG-05-25-2011<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Link<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Http:\/\/www.ScriptingGuys.com\/blog<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>#Requires -Version 2.0<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>#&gt;<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>Add-type -assembly &#8220;Microsoft.Office.Interop.Outlook&#8221; | out-null<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>$olFolders = &#8220;Microsoft.Office.Interop.Outlook.olDefaultFolders&#8221; -as [type] <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>$outlook = new-object -comobject outlook.application<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>$namespace = $outlook.GetNameSpace(&#8220;MAPI&#8221;)<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>$folder = $namespace.getDefaultFolder($olFolders::olFolderSentMail)<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>$folder.items | <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>Select-Object -Property Subject, SentOn, Importance, To<\/span><\/span><\/span><\/span><\/p>\n<p><span style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">} #end function Get-OutlookSentItems<\/span><\/span><\/span><\/p><\/blockquote>\n<p>To use the <b>Get-OutlookSentItems<\/b> function, I call the function and save the results. On my computer, the <b>Get-OutlookSentItems<\/b> function takes a pretty long time to complete. Therefore, I run it only once, and I store the resulting objects into a variable. Here is the code that does that:<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$sentItems = Get-OutlookSentItems<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>I might be interested in how many items I have in my Sent Items folder. I can use the <b>Measure-Object<\/b> cmdlet. I am only interested in the <b>count<\/b> property, so I access it directly as shown here: <\/p>\n<blockquote>\n<p><span lang=\"EN\" style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span>($sentItems | Measure-Object).count<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>On the other hand, because <b>$SentItems<\/b> is a collection of objects, I can use the <b>count<\/b> property from it, and avoid using <b>Measure-Object<\/b>, as shown here:<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>$sentItems.count<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>I can also use normal Windows PowerShell cmdlets to analyze the information that is contained in the Sent Items folder. The following code uses the <b>$sentItems<\/b> variable (previously created) and searches the <b>subject<\/b> field for the string &#8216;2011 Scripting Games&#8217;. It then sorts by the date sent. This sort is descending, which puts the oldest messages at bottom of list. The <b>Select-Object<\/b> cmdlet is then used to choose only the <b>subject<\/b> and <b>sentOn<\/b> properties, and then only the last five messages are displayed. These last five messages are the five oldest messages that meet the string. This code is shown here: <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>$sentItems | where { $_.subject -match &#8216;2011 Scripting Games&#8217; } | <\/span><\/span><\/span><\/p>\n<p><span lang=\"EN\" style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span>sort SentOn -Descending | select subject, senton -last 5<\/span><\/span><\/span><\/p><\/blockquote>\n<p>For ease of use, I uploaded the complete <a target=\"_blank\" href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/a38c361e-667e-4c09-835c-a53cb874faac\">Get-OutlookSentItems function<\/a> to the Scripting Guys Script Repository. <\/p>\n<p>I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, teaches you how to use Windows PowerShell to data mine your Sent Items folder in Microsoft Outlook. Hey, Scripting Guy! I was wondering if I would use Windows PowerShell to process my Sent Items in Outlook. I mean, I think there is some interesting data I could obtain if [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[212,49,3,45],"class_list":["post-13831","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-microsoft-outlook","tag-office","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, teaches you how to use Windows PowerShell to data mine your Sent Items folder in Microsoft Outlook. Hey, Scripting Guy! I was wondering if I would use Windows PowerShell to process my Sent Items in Outlook. I mean, I think there is some interesting data I could obtain if [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13831","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=13831"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13831\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=13831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=13831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=13831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}