powershelloutlookpowershell-2.0outlook-2003

How to get outlook 2003 inbox using powershell


I have used below code to get outlook inbox information using Powershell.

Function Get-OutlookInBox 
{
    Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null 
 $olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type]  
 $outlook = new-object -comobject outlook.application 
 $namespace = $outlook.GetNameSpace("MAPI") 
 $folder = $namespace.getDefaultFolder($olFolders::olFolderInBox) 
 $folder.items |  
 Select-Object -Property Subject, ReceivedTime, Importance, SenderName 
}
$inbox=Get-OutlookInBox
$inbox | Group-Object -Property senderName -NoElement | Sort-Object count

This works perfectly fine in Outlook 2007 ,Win7. However Outlook 2003 XP gives below error.

Add-Type : Could not load file or assembly 'Microsoft.Office.Interop.Outlook, Version=12.0.0.0, Culture=neutral, PublicKey
Token=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

First thing Outlook 2003 is version 11.0 and in error it is showing Version-12.0.0.0. Is there anything else i should be doing.


Solution

  • Try to explictly specify the version of the interop assembly you want:

    Add-Type -AssemblyName ('Microsoft.Office.Interop.Outlook, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
    

    Check the content of your GAC and see what version(s) of the interop assemblies you have there.