I am trying to access my outlook from powershell

I am trying to access Microsoft outlook from Powershell but I am not able to get access to it. I don’t know what is the problem. It is a company firewall or I am not writing a correct powershell command for access Outlook. Any help appreciated???

Set-ExecutionPolicy RemoteSigned

# use MAPI name space
$outlook = new-object -com outlook.application; 
$mapi = $outlook.GetNameSpace("MAPI");

# link to the folder
$olFolderPath = "\\shantanu.gupta@EarthSQL.com\Inbox"

I am getting this error
new-object : Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server
execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
At C:\Users\ShantanuGupta\Desktop\EmailTesting.ps1:4 char:12

  • $outlook = new-object -com outlook.application;
  •        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : ResourceUnavailable: (:slight_smile: [New-Object], COMException
    • FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression.
At C:\Users\ShantanuGupta\Desktop\EmailTesting.ps1:5 char:1

  • $mapi = $outlook.GetNameSpace(“MAPI”);
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull

Is outlook already open? If so, try closing it and see if you can access it. if both are true, I would guess you’re powershell prompt is “running as admin” where outlook isn’t.