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

Testing and Sending email via SMTP using Opportunistic TLS and oAuth in Office365 with PowerShell

As well as EWS and Remote PowerShell (RPS) other mail protocols POP3, IMAP and SMTP have had OAuth authentication enabled in Exchange Online (Official announcement here ). A while ago I created  this script that used Opportunistic TLS to perform a Telnet style test against a SMTP server using SMTP AUTH. Now that oAuth authentication has been enabled in office365 I've updated this script to be able to use oAuth instead of SMTP Auth to test against Office365. I've also included a function to actually send a Message. Token Acquisition  To Send a Mail using oAuth you first need to get an Access token from Azure AD there are plenty of ways of doing this in PowerShell. You could use a library like MSAL or ADAL (just google your favoured method) or use a library less approach which I've included with this script . Whatever way you do this you need to make sure that your application registration  https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-

How to test SMTP using Opportunistic TLS with Powershell and grab the public certificate a SMTP server is using

Most email services these day employ Opportunistic TLS when trying to send Messages which means that wherever possible the Messages will be encrypted rather then the plain text legacy of SMTP.  This method was defined in RFC 3207 "SMTP Service Extension for Secure SMTP over Transport Layer Security" and  there's a quite a good explanation of Opportunistic TLS on Wikipedia  https://en.wikipedia.org/wiki/Opportunistic_TLS .  This is used for both Server to Server (eg MTA to MTA) and Client to server (Eg a Message client like Outlook which acts as a MSA) the later being generally Authenticated. Basically it allows you to have a normal plain text SMTP conversation that is then upgraded to TLS using the STARTTLS verb. Not all servers will support this verb so if its not supported then a message is just sent as Plain text. TLS relies on PKI certificates and the administrative issue s that come around certificate management like expired certificates which is why I wrote th

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 Graph is limited to a m
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.