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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s