Instantiating Outlook fails in Powershell Studio but works in VS Code

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 10 months and 2 weeks 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
EBO_RogueOne
Posts: 2
Last visit: Thu Mar 07, 2024 1:55 pm

Instantiating Outlook fails in Powershell Studio but works in VS Code

Post by EBO_RogueOne »

Hello All!

I'm new to PowerShell Studio but I have been using PowerShell for years with other IDEs, originally PowerGui and then VS Code. I'm not a fan of the VS Code environment which is why I switched to PowerShell Studio. I'm sure there are nuances I'm oblivious to which is why I thought I'd seek help here.

I have a process that connects to MS Outlook to search messages for keywords for audit purposes. "This" is the first time running the process in PS Studio, and I have encountered an error that does not happen in VS Code or the PowerShell ISE. When I run the code below, at the "New-Object" line in PS Studio I get the following error message:

  1. >> Platform: V5 64Bit (STA)
  2. ERROR: New-Object : Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005
  3. ERROR: Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
  4. PS1_Sandbox.ps1 (6, 8): ERROR: At Line: 6 char: 8
  5. ERROR: + $ol = (New-Object -comobject Outlook.Application)
  6. ERROR: +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. ERROR:     + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
  8. ERROR:     + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
  9. ERROR:
  1. [void](Add-Type -assembly "Microsoft.Office.Interop.Outlook")
  2. $ol = (New-Object -comobject Outlook.Application)

When this identical code is executed in VS Code it works as expected with no no exceptions. I guess my question is, is there something I need to define in PS Studio, such as adding a reference library (as in Visual Studio C# "References" - not a using statement)? I haven't found anything but I'm new to the IDE so I may be missing something. Or, is there additional PS1, or PS1 I am unaware of needed? I wouldn't think so of the latter as it works in VS Code and have found nothing to indicate otherwise with Googling (StackOverflow, etc etc), but I very well could be missing something.

I would appreciate any feedback and advice, and thank you!!!


Environment specs:
Powershell Studio v5.8.207
VSCode 1.78.0
Windows 10 Enterprise v21H2 OSBuild 19044.2728
EBO_RogueOne
Posts: 2
Last visit: Thu Mar 07, 2024 1:55 pm

Re: Instantiating Outlook fails in Powershell Studio but works in VS Code

Post by EBO_RogueOne »

Additional PS info:

PSVersion 5.1.19041.2673
PSEdition Desktop
BuildVersion 10.0.19041.2673
CLRVersion 4.0.30319.42000
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Instantiating Outlook fails in Powershell Studio but works in VS Code

Post by Alexander Riedel »

Most likely a permission issue. Check you system log for details.
You may have to use DComCnfg to go give the part of PowerShell Studio that runs scripts (ScriptDriver*.exe) permission to instantiate this COM object.
See https://learn.microsoft.com/en-us/windo ... g-dcomcnfg
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 10 months and 2 weeks 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