The doghouse: Vagaries of the Excel COM interface

Wow. It's been a while since I've seen a more fragrant turd than the COM interface exposed by Excel which would, theoretically, allow you to interact with workbooks from e.g. PowerShell.
Theoretically is the key word, I'm sad to say. In practice, it's so buggy and poorly designed that you might save more time if you did what you wanted by hand.
Let's start with the simplest possible script:
$xl = New-Object -com Excel.Application $wb = $xl.Workbooks.Open("C:\Temp\file.xls") What does this do?
Each invocation of this script creates a copy of Excel which then just hangs around. Indefinitely. Like this:
If you just created the COM object, Excel would exit. But since you opened a workbook, it does not. Not even closing the PowerShell window exits these instances. You have to actually go and kill them using a task manager application.
Okay. Let's try modifying the script to close the workbook:
$xl = New-Object -com Excel.Application $wb = $xl.Wor…
Theoretically is the key word, I'm sad to say. In practice, it's so buggy and poorly designed that you might save more time if you did what you wanted by hand.
Let's start with the simplest possible script:
$xl = New-Object -com Excel.Application $wb = $xl.Workbooks.Open("C:\Temp\file.xls") What does this do?
Each invocation of this script creates a copy of Excel which then just hangs around. Indefinitely. Like this:
If you just created the COM object, Excel would exit. But since you opened a workbook, it does not. Not even closing the PowerShell window exits these instances. You have to actually go and kill them using a task manager application.
Okay. Let's try modifying the script to close the workbook:
$xl = New-Object -com Excel.Application $wb = $xl.Wor…