Using Powershell to read outlook 2010 emails in Windows 7

Answered Using Powershell to read outlook 2010 emails in Windows 7

  • Wednesday, January 23, 2013 10:57 PM
     
     

    I have been using the same script for accessing the emails in Windows XP environment which still works fine. 

    However, I am trying to do the same in Windows 7, outlook 2010 and have been getting errors. Please help.

    [Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.OutlookViewCtl") | out-null
    $olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
    $outlook = New-Object -comobject outlook.application
    $mapi = $outlook.GetNamespace("MAPI")

    I get the following error:

    New-Object : Cannot load COM type outlook.application.
    At line:8 char:16
    + $outlook = New-Object <<<<  -comobject outlook.application
        + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
        + FullyQualifiedErrorId : CannotLoadComObjectType,Microsoft.PowerShell.Commands.NewObjectCommand

    You cannot call a method on a null-valued expression.
    At line:9 char:21
    + $mapi = $outlook.GetNamespace <<<< ("MAPI")
        + CategoryInfo          : InvalidOperation: (GetNamespace:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    Thank you in advance!

    AJ

All Replies

  • Wednesday, January 23, 2013 10:58 PM
     
     

    I have been using the same script for accessing the emails in Windows XP environment which still works fine. 

    However, I am trying to do the same in Windows 7, outlook 2010 and have been getting errors. Please help.

    [Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.OutlookViewCtl") | out-null
    $olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
    $outlook = New-Object -comobject outlook.application
    $mapi = $outlook.GetNamespace("MAPI")

    I get the following error:

    New-Object : Cannot load COM type outlook.application.
    At line:8 char:16
    + $outlook = New-Object <<<<  -comobject outlook.application
        + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
        + FullyQualifiedErrorId : CannotLoadComObjectType,Microsoft.PowerShell.Commands.NewObjectCommand

    You cannot call a method on a null-valued expression.
    At line:9 char:21
    + $mapi = $outlook.GetNamespace <<<< ("MAPI")
        + CategoryInfo          : InvalidOperation: (GetNamespace:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    Thank you in advance!

    AJ

  • Wednesday, January 23, 2013 11:05 PM
    Moderator
     
     Answered

    Hi,

    I'm going to attempt psychic debugging and guess that your Windows 7 machine is x64 and you're running the script from a 64-bit PowerShell window. If that's the case, try running your script from a 32-bit PowerShell window.

    Bill