Skip to main content

Creating a Report of the WhiteSpace in all the PST's and OST in the default Outlook profile

One of my favorite development utilities is mfcMapi which along with OutlookSpy are invaluable utilities to use when doing any Exchange development. Along with mfcMapi Stephan also has a utility called mrMapi which provides console access to a number of useful MAPI functions . Last week he added a new feature to report on the files sizes and white-space inside a PST or OST based on the Header information in the file http://blogs.msdn.com/b/stephen_griffin/archive/2013/01/28/january-2013-release-of-mfcmapi-and-mrmapi.aspx.

I thought this was a really useful thing as it can be a little bit confounding sometimes looking at PST files that have been produced by exporting a Mailbox and comparing that against the actual mailbox size. So I decided to put a script together that would get all the PST and OST file paths for default Outlook profile. Run those filepaths through mrMapi and parse console Output and the put together a HTML report of the information that ended up looking something like this (all sizes are in MB)


To use this script you need the latest copy of mrMapi from http://mfcmapi.codeplex.com/ and you need to adjust the following varible in the script to the path where you downloaded it to

$mrMapiPath = "c:\mfcmapi\mrmapi.exe"

I've put a download of the script here the code itself looks like

  1. $mrMapiPath = "c:\mfcmapi\mrmapi.exe"  
  2. $rptCollection = @()  
  3.   
  4. function ParseBitValue($String){  
  5.     $numItempattern = '(?=\().*(?=bytes)'  
  6.     $matchedItemsNumber = [regex]::matches($String, $numItempattern)   
  7.     $bytes = [INT64]$matchedItemsNumber[0].Value.Replace("(","").Replace(",","") /1MB  
  8.     return [System.Math]::Round($bytes,2)  
  9. }  
  10.   
  11. $Encode = new-object System.Text.UnicodeEncoding  
  12. ##Check for Office 2013  
  13. $RootKey = "Software\Microsoft\Office\15.0\Outlook\Profiles\" 
  14. $pkProfileskey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($RootKey, $true) 
  15.  
  16. if($pkProfileskey -eq $null){ 
  17.     $RootKey = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" 
  18.     $pkProfileskey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($RootKey, $true) 
  19.     $defProf = $pkProfileskey.GetValue("DefaultProfile") 
  20. } 
  21. else{ 
  22.     $OutDefault = "Software\Microsoft\Office\15.0\Outlook\" 
  23.     $pkProfileskey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($OutDefault, $true) 
  24.     $defProf = $pkProfileskey.GetValue("DefaultProfile") 
  25. } 
  26. $defProf 
  27. $pkSubProfilekey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey(($RootKey + "\\" + $defProf), $true) 
  28. foreach($Valuekey in $pkSubProfilekey.getSubKeyNames()){ 
  29.     $pkSubValueKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey(($RootKey + "\\" + $defProf + "\\" + $Valuekey ), $true) 
  30.     $pstVal = $pkSubValueKey.GetValue("001f6700") 
  31.     if($pstVal -ne $null) 
  32.     { 
  33.         $pstPath = $Encode.GetString($pstVal)  
  34.         $fnFileName = $pstPath.Replace([System.Convert]::ToChar(0x0).ToString().Trim(), "")      
  35.         if(Test-Path $fnFileName){ 
  36.             $rptObj = "" | Select Name,Type,FilePath,FileSize,FreeSpace,PrecentFree 
  37.             $fiInfo = ([System.IO.FileInfo]$fnFileName)  
  38.             $rptObj.Name = $fiInfo.Name 
  39.             $rptObj.FilePath = $fiInfo.DirectoryName 
  40.             $rptObj.Type = "PST"             
  41.             iex ($mrMapiPath + " -pst -i '$pstPath'") | foreach-object{ 
  42.                 if($_.Contains("=")){ 
  43.                     $splitArray = $_.Split("=")              
  44.                     switch ($splitArray[0].Trim()){                  
  45.                         "File Size" { 
  46.                                 $rptObj.FileSize =  ParseBitValue($splitArray[1].Trim())  
  47.                             } 
  48.                         "Free Space" { 
  49.                                 $rptObj.FreeSpace = ParseBitValue($splitArray[1].Trim())  
  50.                             } 
  51.                         "Percent free" { 
  52.                                 $rptObj.PrecentFree = $splitArray[1].Trim() 
  53.                             } 
  54.                     } 
  55.                      
  56.                 } 
  57.             } 
  58.             $rptCollection += $rptObj 
  59.         } 
  60.     } 
  61.     ## Check OSTs 
  62.     $ostVal = $pkSubValueKey.GetValue("001f6610") 
  63.     if($ostVal -ne $null) 
  64.     { 
  65.         $ostPath = $Encode.GetString($ostVal)  
  66.         $fnFileName = $ostPath.Replace([System.Convert]::ToChar(0x0).ToString().Trim(), "")      
  67.         if(Test-Path $fnFileName){ 
  68.             $rptObj = "" | Select Name,Type,FilePath,FileSize,FreeSpace,PrecentFree 
  69.             $fiInfo = ([System.IO.FileInfo]$fnFileName)  
  70.             $rptObj.Name = $fiInfo.Name 
  71.             $rptObj.FilePath = $fiInfo.DirectoryName 
  72.             $rptObj.Type = "OST" 
  73.             iex ($mrMapiPath + " -pst -i `"$fnFileName`"") | foreach-object{ 
  74.                 if($_.Contains("=")){ 
  75.                     $splitArray = $_.Split("=")              
  76.                      
  77.                     switch ($splitArray[0].Trim()){                  
  78.                         "File Size" { 
  79.                                 $rptObj.FileSize =  ParseBitValue($splitArray[1].Trim())  
  80.                             } 
  81.                         "Free Space" { 
  82.                                 $rptObj.FreeSpace = ParseBitValue($splitArray[1].Trim())  
  83.                             } 
  84.                         "Percent free" { 
  85.                                 $rptObj.PrecentFree = $splitArray[1].Trim() 
  86.                             } 
  87.                     } 
  88.                      
  89.                 } 
  90.             } 
  91.             $rptCollection += $rptObj 
  92.         } 
  93.     } 
  94. } 
  95.  
  96.  
  97. $tableStyle = @"  
  98. <style>  
  99. BODY{background-color:white;}  
  100. TABLE{border-width: 1px;  
  101. border-style: solid;  
  102. border-color: black;  
  103. border-collapse: collapse;  
  104. }  
  105. TH{border-width: 1px;  
  106. padding: 10px;  
  107. border-style: solid;  
  108. border-color: black;  
  109. background-color:thistle  
  110. }  
  111. TD{border-width: 1px;  
  112. padding: 2px;  
  113. border-style: solid;  
  114. border-color: black;  
  115. background-color:white  
  116. }  
  117. </style>  
  118. "@ 
  119.  
  120. $body = @"  
  121. <p style="font-size:25px;family:calibri;color:#ff9100">  
  122. $TableHeader  
  123. </p>  
  124. "@  
  125.   
  126. $rptCollection | ConvertTo-HTML -head $tableStyle –body $body |Out-File c:\temp\ProfileReport-$defProf.htm  

Popular posts from this blog

The MailboxConcurrency limit and using Batching in the Microsoft Graph API

If your getting an error such as Application is over its MailboxConcurrency limit while using the Microsoft Graph API this post may help you understand why. Background   The Mailbox  concurrency limit when your using the Graph API is 4 as per https://docs.microsoft.com/en-us/graph/throttling#outlook-service-limits . This is evaluated for each app ID and mailbox combination so this means you can have different apps running under the same credentials and the poor behavior of one won't cause the other to be throttled. If you compared that to EWS you could have up to 27 concurrent connections but they are shared across all apps on a first come first served basis. Batching Batching in the Graph API is a way of combining multiple requests into a single HTTP request. Batching in the Exchange Mail API's EWS and MAPI has been around for a long time and its common, for email Apps to process large numbers of smaller items for a variety of reasons.  Batching in the Gr...

EWS-FAI Module for browsing and updating Exchange Folder Associated Items from PowerShell

Folder Associated Items are hidden Items in Exchange Mailbox folders that are commonly used to hold configuration settings for various Mailbox Clients and services that use Mailboxes. Some common examples of FAI's are Categories,OWA Signatures and WorkHours there is some more detailed documentation in the https://msdn.microsoft.com/en-us/library/cc463899(v=exchg.80).aspx protocol document. In EWS these configuration items can be accessed via the UserConfiguration operation https://msdn.microsoft.com/en-us/library/office/dd899439(v=exchg.150).aspx which will give you access to either the RoamingDictionary, XMLStream or BinaryStream data properties that holds the configuration depending on what type of FAI data is being stored. I've written a number of scripts over the years that target particular FAI's (eg this one that reads the workhours  http://gsexdev.blogspot.com.au/2015/11/finding-timezone-being-used-in-mailbox.html is a good example ) but I didn't have a gene...

Sending a MimeMessage via the Microsoft Graph using the Graph SDK, MimeKit and MSAL

One of the new features added to the Microsoft Graph recently was the ability to create and send Mime Messages (you have been able to get Message as Mime for a while). This is useful in a number of different scenarios especially when trying to create a Message with inline Images which has historically been hard to do with both the Graph and EWS (if you don't use MIME). It also opens up using SMIME for encryption and a more easy migration path for sending using SMTP in some apps. MimeKit is a great open source library for parsing and creating MIME messages so it offers a really easy solution for tackling this issue. The current documentation on Send message via MIME lacks any real sample so I've put together a quick console app that use MSAL, MIME kit and the Graph SDK to send a Message via MIME. As the current Graph SDK also doesn't support sending via MIME either there is a workaround for this in the future my guess is this will be supported.
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.