Saturday, 20 March 2010

Get-OutlookStores.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script uses the Outlook COM object to  
  4.     display the data stores in the current profile 
  5. .DESCRIPTION 
  6.     This script creates an Outlook object, displays 
  7.     user information, and the stores currently 
  8.     attached to the profile. 
  9. .NOTES 
  10.     File Name  : Get-OutlookStores.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16. .EXAMPLE 
  17.     PSH [C:\foo]: .\Get-OutlookStores.ps1' 
  18.     Current profile has the following configured accounts: 
  19.  
  20.     Account Type           User Name        SMTP Address 
  21.     ------------           ---------        ------------ 
  22.     Microsoft Exchange     Thomas.Lee       Thomas.Lee@cookham.net 
  23.     thomas_lee@hotmail.com Thomas Lee (MSN) thomas_lee@hotmail.com 
  24.  
  25.     Exchange Offile Folder Store: 
  26.     C:\Users\tfl\AppData\Local\Microsoft\Outlook\outlook0.ost 
  27.     
  28.     PST Files 
  29.     Display Name    File Path  
  30.     ------------    --------- 
  31.     Archive Folders C:\Users\tfl\AppData\Local\Microsoft\Outlook\archive.pst 
  32. #> 
  33.  
  34. ## 
  35. # Begin Script 
  36. ## 
  37.  
  38. # Create Outlook object 
  39. $Outlook = New-Object -ComObject Outlook.Application 
  40. $stores = $Outlook.Session.Stores 
  41. $accounts = $outlook.session.accounts 
  42.  
  43. # Basic information 
  44. "Current profile has the following configured accounts:" 
  45. $dn = @{label = "Account Type"; expression={$_.displayname}} 
  46. $un = @{label = "User Name"; expression = {$_.username}} 
  47. $sm = @{label = "SMTP Address"; expression = {$_.smtpaddress}} 
  48. $accounts | Format-Table -AutoSize $dn,$un,$sm 
  49. # Check number of stores > 0 
  50. if ($stores.Count -le 0) {"No stores found"; return
  51.  
  52. # Outlook Off-Line folder store 
  53. $ost = $stores | where{$_.filepath -match ".ost$"
  54. if (!$ost
  55.    "No Outlook Offline Folder store found" 
  56. else 
  57.    "Exchange Offile Folder Store:" 
  58.    $ost | ft filepath -HideTableHeaders 
  59.   } 
  60.  
  61. # PST Files 
  62. $pst = $stores | where {$_.filepath -match ".pst$"
  63. if (!$pst
  64.   { 
  65.     "No PST files found" 
  66.   } 
  67. else 
  68.   { 
  69.     "PST Files" 
  70.     $dn = @{label = "Display Name"; expression={$_.displayname}} 
  71.     $fn = @{label = "File Path"; expression={$_.filepath}} 
  72.     $pst | ft $dn,$fn        
  73.   } 
  74. # End Script

1 comment:

Rick said...

Perfect. Now I don't have to "re-invent the wheel"!