简体   繁体   中英

New-Object not assigned to a variable PowerShell

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM