# GetNamespace("MAPI") error with Outlook

**URL:** <https://forums.powershell.org/t/getnamespace-mapi-error-with-outlook/23192>\
**Category:** PowerShell Help\
**Created:** [November 20, 2023, 8:29am UTC](https://forums.powershell.org/t/getnamespace-mapi-error-with-outlook/23192 "2023-11-20T08:29:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![UlrichDemlehner](https://avatars.discourse-cdn.com/v4/letter/u/c2a13f/32.png) [@UlrichDemlehner](https://forums.powershell.org/u/UlrichDemlehner)\
**Post date:** [November 20, 2023, 8:29am UTC](https://forums.powershell.org/t/getnamespace-mapi-error-with-outlook/23192/1 "2023-11-20T08:29:37Z")

</div>

My simple 2 lines code:

$outlook = New-Object -ComObject Outlook.Application  
$namespace = $outlook.GetNamespace(“MAPI”)

The GetNamespace(“MAPI”) command leads to the error message:

Ausnahme beim Aufrufen von “GetNamespace” mit 1 Argument(en): “Das COM-Objekt des Typs “Microsoft.Office.Interop.Outlook.ApplicationClass” kann nicht in den Schnittstellentyp  
“Microsoft.Office.Interop.Outlook.\_Application” umgewandelt werden. Dieser Vorgang konnte nicht durchgeführt werden, da der QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle  
mit der IID “{00063001-0000-0000-C000-000000000046}” aufgrund des folgenden Fehlers nicht durchgeführt werden konnte: Element nicht gefunden. (Ausnahme von HRESULT: 0x8002802B  
(TYPE\_E\_ELEMENTNOTFOUND)).”  
In Zeile:2 Zeichen:1

- $namespace = $outlook.GetNamespace(“MAPI”)
- 

```auto
  + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
  + FullyQualifiedErrorId : InvalidCastException

```

This happens with both a 32 and a 64 bit version of Powershell. The equivalent good old 32 bit VBScript code

Dim outlookApp: Set outlookApp = CreateObject(“Outlook.Application”)  
Dim namespace: Set namespace = outlookApp.GetNamespace(“MAPI”)

has no problems at all. I’m running Outlook 2016 32 bit on Win10 64 bit.

Thanks for your comments!

Ulrich

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 20, 2023, 9:37am UTC](https://forums.powershell.org/t/getnamespace-mapi-error-with-outlook/23192/2 "2023-11-20T09:37:18Z")

</div>

Ulrich,  
Servus & Welcome to the forum. 👋🏼

Since this is an English forum error messages in foreign languages are problematic. I’d recommend to ask the question in a German forum or translate the German parts of the error message.

Regardless of that - what do you actually want to do? But I should admit in advance that I don’t have any experiences automating office.  
Automating MSFT Office is AFAIK best done with the office internal scripting language VBA. It might be a good idea as well to find a particularily Office related forum.

---

<div class="post-metadata">

**Author:** ![UlrichDemlehner](https://avatars.discourse-cdn.com/v4/letter/u/c2a13f/32.png) [@UlrichDemlehner](https://forums.powershell.org/u/UlrichDemlehner)\
**Post date:** [November 20, 2023, 10:12am UTC](https://forums.powershell.org/t/getnamespace-mapi-error-with-outlook/23192/3 "2023-11-20T10:12:01Z")

</div>

> [@UlrichDemlehner](#):
>
> Ausnahme beim Aufrufen von “GetNamespace” mit 1 Argument(en): “Das COM-Objekt des Typs “Microsoft.Office.Interop.Outlook.ApplicationClass” kann nicht in den Schnittstellentyp  
> “Microsoft.Office.Interop.Outlook.\_Application” umgewandelt werden. Dieser Vorgang konnte nicht durchgeführt werden, da der QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle  
> mit der IID “{00063001-0000-0000-C000-000000000046}” aufgrund des folgenden Fehlers nicht durchgeführt werden konnte: Element nicht gefunden. (Ausnahme von HRESULT: 0x8002802B  
> (TYPE\_E\_ELEMENTNOTFOUND)).”

Sorry, but my assumption was that somebody who has expertise with those COM problems will be able to identify the error message even if it is in mixed German/English. Google translates as

```auto
Exception when calling “GetNamespace” with 1 argument(s): “The COM object of type “Microsoft.Office.Interop.Outlook.ApplicationClass” cannot be included in the interface type
“Microsoft.Office.Interop.Outlook._Application” can be converted. This operation could not be performed because the QueryInterface call went to the COM component for the interface
with the IID “{00063001-0000-0000-C000-000000000046}” could not be performed due to the following error: Element not found. (Exception from HRESULT: 0x8002802B
(TYPE_E_ELEMENTNOTFOUND)).”

```

and this translation appears to match the original English error message quite well.

> [@Olaf](#):
>
> Regardless of that - what do you actually want to do? But I should admit in advance that I don’t have any experiences automating office.

Exactly that: automating office, in particular Outlook. The problem is that this GetNamespace call is basically the key to all Outlook objects and if that key does not fit, there is no way to work with the other Outlook objects.

> [@Olaf](#):
>
> Automating MSFT Office is AFAIK best done with the office internal scripting language VBA. It might be a good idea as well to find a particularily Office related forum.

Sure, that has been my work around. But I’m simply curious if somebody has a solution for PowerShell.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 20, 2023, 10:46am UTC](https://forums.powershell.org/t/getnamespace-mapi-error-with-outlook/23192/4 "2023-11-20T10:46:21Z")

</div>

> [@UlrichDemlehner](#):
>
> Sorry, but my assumption was that somebody who has expertise with those COM problems will be able to identify the error message even if it is in mixed German/English.

OK, but wouldn’t you agree that it is a kind of nice and polite when you make it as easy as possible for someone to help you? 😉

> [@UlrichDemlehner](#):
>
> and this translation appears to match the original English error message quite well.

Great. You may add some more info about your environment. The error might be related to a particular version.

> [@UlrichDemlehner](#):
>
> Sure, that has been my work around. But I’m simply curious if somebody has a solution for PowerShell.

OK, let’s wait if there is someone able to help.  
Good luck. 🤞🏼

---

<div class="post-metadata">

**Author:** ![UlrichDemlehner](https://avatars.discourse-cdn.com/v4/letter/u/c2a13f/32.png) [@UlrichDemlehner](https://forums.powershell.org/u/UlrichDemlehner)\
**Post date:** [November 20, 2023, 11:02am UTC](https://forums.powershell.org/t/getnamespace-mapi-error-with-outlook/23192/5 "2023-11-20T11:02:34Z")

</div>

> [@Olaf](#):
>
> OK, but wouldn’t you agree that it is a kind of nice and polite when you make it as easy as possible for someone to help you?

I see your point …

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [November 20, 2023, 4:34pm UTC](https://forums.powershell.org/t/getnamespace-mapi-error-with-outlook/23192/6 "2023-11-20T16:34:48Z")

</div>

I can’t replicate this error although my version of Office is 64-bit, not sure if that’s relevant.

Google search results for the error suggest that repairing the Office installation might resolve the problem (at least temporarily). Worth a try?

---

<div class="post-metadata">

**Author:** ![UlrichDemlehner](https://avatars.discourse-cdn.com/v4/letter/u/c2a13f/32.png) [@UlrichDemlehner](https://forums.powershell.org/u/UlrichDemlehner)\
**Post date:** [November 20, 2023, 5:25pm UTC](https://forums.powershell.org/t/getnamespace-mapi-error-with-outlook/23192/7 "2023-11-20T17:25:19Z")

</div>

At keast it’s interesting that you found something which I did not. This alone is a bit strange according to my experience. So it appears that I probably have a very strange mixture of COM objects on my machine that leads to the problem. I’m not really sure if it’s worth a repair or complete re-build of the machine since the work-around with VBA or VBScript works quite well.

Thanks for your comment.

Ulrich

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 20, 2023, 5:32pm UTC](https://forums.powershell.org/t/getnamespace-mapi-error-with-outlook/23192/8 "2023-11-20T17:32:58Z")

</div>

> [@UlrichDemlehner](#):
>
> At keast it’s interesting that you found something which I did not.

In the meantime I tested the two lines of code as well on my work PC and couldn’t reproduce your error neither. 🤷🏼‍♂️

---

<div class="post-metadata">

**Author:** ![UlrichDemlehner](https://avatars.discourse-cdn.com/v4/letter/u/c2a13f/32.png) [@UlrichDemlehner](https://forums.powershell.org/u/UlrichDemlehner)\
**Post date:** [November 20, 2023, 6:12pm UTC](https://forums.powershell.org/t/getnamespace-mapi-error-with-outlook/23192/9 "2023-11-20T18:12:41Z")

</div>

I installed the latest version of PowerShell and the problem has disappeared though I use the 64 bit PowerShell with my 32 bit Outlook. Jumping to a conclusion that may be completely wrong, but the problem obviously were not my Outlook COM objects but the way PowerShell worked with those. Confusing stuff …

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:14pm UTC](https://forums.powershell.org/t/getnamespace-mapi-error-with-outlook/23192/10 "2024-05-16T20:14:34Z")

</div>

Closed on May 16, 2024, 8:14pm UTC


