title: Remove password protection from an outlook .pst file programmatically
body: <p>I am working on a project which involves reading through a lot of Outlook.pst files.</p>
  
  <p>These files are all password protected but I have the password in question. The problem is that it's very tedious process opening each file in Outlook and enter in the password in order to read the data.</p>
  
  <p>Now I'm thinking if there is any way to create a script which opens each .pst file for me automatically, enters in the password and saves the file again without the password.</p>
  
  <p>I've been googling around and don't seem to find any solution to my problem, looks like the MAPI outlook.application interface is poorly documented. So far I've seen a PowerShell script doing this with an Excel application from <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2007/04/12/how-can-i-remove-the-password-when-opening-an-excel-spreadsheet.aspx" rel="nofollow">technet</a></p>
  
  <pre><code>$comments = @' 
  Script name: Remove-Password.ps1 
  Created on: Tuesday, July 03, 2007 
  Author: Kent Finkle 
  Purpose: How can I use Windows Powershell to 
  Remove the Password When Opening an Excel Spreadsheet? 
  '@ 
  #----------------------------------------------------- 
  function Release-Ref ($ref) { 
  ([System.Runtime.InteropServices.Marshal]::ReleaseComObject( 
  [System.__ComObject]$ref) -gt 0) 
  [System.GC]::Collect() 
  [System.GC]::WaitForPendingFinalizers()  
  } 
  #----------------------------------------------------- 
  $xl = new-object -comobject excel.application 
  $xl.Visible = $True 
  $xl.DisplayAlerts = $False 
  $wb = $xl.Workbooks.Open("C:\Scripts\Test.xls",0,$False,1,"%reTG54w") 
  $wb.Password = "" 
  $a = $wb.SaveAs( "C:\Scripts\Test.xls") 
  $a = Release-Ref($wb) 
  $a = Release-Ref($xl) 
  </code></pre>
  
  <p>Possibly I could apply this to MAPI with something similar to this</p>
  
  <pre><code>$outlook = new-object -com outlook.application;
  $ns = $outlook.GetNameSpace("MAPI");
  $fSaveMe = $ns.GetDefaultFolder($olFolderInbox).Folders.Item("Save Me")
  $fSaveMe.Items | foreach { [void]$_.Move($ns.Folders.Item("Legal")) }
  </code></pre>
  
  <p>Is there anyone that has had a similar problem ? The potential solution doesn't have to be in PowerShell, it can be in Python, Perl, Java, C# or just about anything as long as it gets the job done :)</p>