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...

Exporting and Uploading Mailbox Items using Exchange Web Services using the new ExportItems and UploadItems operations in Exchange 2010 SP1

Two new EWS Operations ExportItems and UploadItems where introduced in Exchange 2010 SP1 that allowed you to do a number of useful things that where previously not possible using Exchange Web Services. Any object that Exchange stores is basically a collection of properties for example a message object is a collection of Message properties, Recipient properties and Attachment properties with a few meta properties that describe the underlying storage thrown in. Normally when using EWS you can access these properties in a number of a ways eg one example is using the strongly type objects such as emailmessage that presents the underlying properties in an intuitive way that's easy to use. Another way is using Extended Properties to access the underlying properties directly. However previously in EWS there was no method to access every property of a message hence there is no way to export or import an item and maintain full fidelity of every property on that item (you could export the...

EWS Create Mailbox folder Powershell module for Exchange and Office365 Mailboxes

This is a rollup post for a couple of scripts I've posted in the past for creating folders using EWS in an Exchange OnPremise or Exchange online Cloud mailbox. It can do the following Create a Folder in the Root of the Mailbox Create-Folder -Mailboxname mailbox@domain.com -NewFolderName test Create a Folder as a SubFolder of the Inbox Create-Folder -Mailboxname mailbox@domain.com -NewFolderName test -ParentFolder '\Inbox' Create a Folder as a SubFolder of the Inbox using EWS Impersonation Create-Folder -Mailboxname mailbox@domain.com -NewFolderName test -ParentFolder '\Inbox' -useImpersonation Create a new Contacts Folder as a SubFolder of the Mailboxes Contacts Folder Create-Folder -Mailboxname mailbox@domain.com -NewFolderName test -ParentFolder '\Contacts' -FolderClass IPF.Contact Create a new Calendar Folder as a SubFolder of the Mailboxes Calendar Folder Create-Folder -Mailboxname mailbox@domain.com -NewFolderName test -Parent...
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.