0

I apologize in advanced if this is a stupid question, but I was wondering is there a way to find objects created in a session of PowerShell that are not assigned to a variable?

for instance:

New-Object -TypeName WinSCP.Session

that would create an object, but with it not assigned to a variable, how do I .Dispose() it? is there a way? Or does that Object just remain until I close the PSSession?

I know with this particular class, there is a default timeout of 1 minute, but if that where not the case, what would happen?

2
  • 2
    What's provoking the question? If you don't assign it to a variable, the .NET framework will automatically dispose of it. Commented Sep 4, 2014 at 19:57
  • this all makes sense, and I was on the right track, the reason I asked is because I am working on a wrapper for WinSCP, and I wrote a function that returns a WinSCP.Session Object, however, if you don't assign it to a variable, you cannot manipulate it, IE New-WinSCPSession -HostName "myHost". but if you assign it to a variable, IE $x = New-WinSCPSession -HostName "myHost", it can then be manipulated with $x.GetFiles(). I was just trying to protect against Undispossed objects. Thanks for all the input. Commented Sep 5, 2014 at 19:05

1 Answer 1

2

If you've run the command in the console, the object is gone, and can't be retrieved. I don't know what PowerShell does with disposable objects when they're no longer being used. If you close and re-open your console, the non-managed resources used by WinSCP.Session will be removed from memory when the PowerShell process closes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.