PoshCode Archive  Artifact [293bbb8022]

Artifact 293bbb80227b5c908219c2005cfab343366570f6fa379626f2631abb934d6cc4:

  • File Release-ComObject.ps1 — part of check-in [415bc0be80] at 2018-06-10 13:59:38 on branch trunk — Author unknown. (user: redyey size: 775)

# encoding: ascii
# api: powershell
# title: Release-ComObject
# description: Author unknown.
# version: 0.1
# type: function
# author: redyey
# license: CC0
# function: Remove-ComObject
# x-poshcode-id: 5703
# x-archived: 2015-01-24T06:41:52
# x-published: 2015-01-22T02:00:00
#
#
# Release COM Object
function Remove-ComObject {
 # Requires -Version 2.0
 [CmdletBinding()]
 param()
 end {
  Start-Sleep -Milliseconds 500
  [Management.Automation.ScopedItemOptions]$scopedOpt = 'ReadOnly, Constant'
  Get-Variable -Scope 1 | Where-Object {
   $_.Value.pstypenames -contains 'System.__ComObject' -and -not ($scopedOpt -band $_.Options)
  } | Remove-Variable -Scope 1 -Verbose:([Bool]$PSBoundParameters['Verbose'].IsPresent)
  [gc]::Collect()
 }
}