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?
Loading Outlook COM Object
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.
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.
Re: Loading Outlook COM Object
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?
Re: Loading Outlook COM Object
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
Consider this closed
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Loading Outlook COM Object
You should never have to load PowerShell Studio elevated. Just pointing that out.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Loading Outlook COM Object
Additionally you can check if outlook is running:
if(([System.Diagnostics.Process]::GetProcesses()).name | ?{$_ -like 'outlook*'})
{
write-host Outlook is running!
}
if(([System.Diagnostics.Process]::GetProcesses()).name | ?{$_ -like 'outlook*'})
{
write-host Outlook is running!
}
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Loading Outlook COM Object
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.
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.