Get rid of the Excel Com Object, Once and for All

From Technet, November of 2007.

When you run $x.Quit() The Excel com object is left running. This can be a problem.
If you are writing and testing a script, you could wind up with 10-15 or more instance of Excel running in the background. Here is one way of solving that problem.


$x = New-Object -com Excel.Application
$x.Visible = $True
Start-Sleep 5
$x.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($x)
Remove-Variable x