Powershell V3+:
I'm writing a module providing various Cmdlets suiteable for interactive use. What I try to achive is, that variables (objects) are getting destructed without having the user to use remove-variable.
Example:
$object = open-object -someparam
$object # returns something
close-object -reference $object
$object # is not defined anymore - similiar to remove-variable
I could not manage to get the above working, alternative approaches like the below have also failed.
$x = New-Object -TypeName PSCustomObject
$x | Add-Member -type NoteProperty -Name Justsomedata -Value Nomeaning
$x | Add-Member -type ScriptMethod -Name killme -Value { $this = $null }
$x
$x.killme()
$x # :-(
Any suggestions? I want to prevent that there are variables in the users runspace that are not useable anymore.