Powershell | Com-object Excel | opens outlook?

Question:

PROBLEM ONLY APPEARS WHEN NO MAIL ACCOUNT IS CONFIGURED – STILL I WOULD APPRECIATE A SOLUTION

I need some help. I have found a very weird habit of this little Script. And I have absolutely no clue, why this should happen.
If I run through the code posted below, Microsoft Outlook starts. And as long as I don’t terminate the Outlook process the script is stuck! Why would this code, ever, start Outlook?
I am lost!

Thx in advance!

Powershell output after Outlook is terminated:

Answer:

The issue here is that when you run $wb.Worksheets.add() it returns the new worksheet to the pipeline (this is why the Sheet properties are displayed when you kill Outlook).

I believe the MailEnvelope property of the Worksheet is what causes Outlook to open (if you store the Sheet and return the MailEnvelope property, the same behaviour occurs).

To get around this you can store the returned sheet, use the Out-Null cmdlet or cast the worksheet to void: $ws = $wb.Worksheets.add() or
$wb.Worksheets.add() | Out-Null or [void] $wb.Worksheets.add()

Source:

Powershell | Com-object Excel | opens outlook? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply