Summary: Learn how to release a COM object in Windows PowerShell.
My Windows PowerShell automation script uses a COM object. How can I make sure that it releases?
Use the ReleaseCOMObject static method from the Marshal class. Pass it the variable that holds the COM object. Here is an example:
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($doc) | Out-Null