Loading Outlook COM Object

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 2 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
B Daring
Posts: 90
Last visit: Mon Feb 05, 2024 3:00 pm
Answers: 2
Has voted: 1 time

Loading Outlook COM Object

Post by B Daring »

I'm trying to create an email but once it tries to load the outlook.application it fails.

$Outlook = New-Object -comObject Outlook.Application

I get an error on that line stating: "ERROR: New-Object : Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005
ERROR: Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))."

We have another application that calls the COM object just fine and works, so I am not sure it is a permissions problem. Is there anything in Studio I need to add, like a reference to the COM library or something?
User avatar
B Daring
Posts: 90
Last visit: Mon Feb 05, 2024 3:00 pm
Answers: 2
Has voted: 1 time

Re: Loading Outlook COM Object

Post by B Daring »

So, come to find out that if Outlook is open that line will fail. If Outlook is closed that line succeeds. So then leads the question as to how to load the outlook.application as a different user?
User avatar
B Daring
Posts: 90
Last visit: Mon Feb 05, 2024 3:00 pm
Answers: 2
Has voted: 1 time

Re: Loading Outlook COM Object

Post by B Daring »

So I guess I just had to write it out. I was trying to hard and running it in Studio while it was loaded in admin mode. Ran it outside of studio and things ran fine.

Consider this closed :)
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Loading Outlook COM Object

Post by Alexander Riedel »

You should never have to load PowerShell Studio elevated. Just pointing that out.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Loading Outlook COM Object

Post by Alexander Riedel »

Additionally you can check if outlook is running:
if(([System.Diagnostics.Process]::GetProcesses()).name | ?{$_ -like 'outlook*'})
{
write-host Outlook is running!
}
Alexander Riedel
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Loading Outlook COM Object

Post by jvierra »

You might want to consider the following issues and suggestions.

You cannot load two copies of Outlook in one session under tw9o user accounts. That is a security restriction. Outlook does not allow account "spoofing".

Never load Outlook as an 3elevated Admin. It is a serious security threat. I haven't tried but I think the current version of Outlook will not load in an elevated session.

You cannot load Outlook without a full UI. This has been documented by Microsoft. You cannot run Outlook as a service either due to the same issues.

Perhaps it would be best if you described why you need to load Outlook as a different user. Access to a foreign mailbox is done by authorization in Exchange. Any local copy of Outlook can access any authorized user mailbox and folders directly. This is the Microsoft intended security context.

For direct programmatic access to Exchange mailboxes there are PS modules and other API's that give direct access to all user mailboxes and folders.
This topic is 2 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked