When working in a regular PowerShell console, variables created within a script will be automatically cleared out when the script terminates unless they are elevated to a greater scope. However, this appears to not be the case within the console in the PowerShell ISE. After I've run a script, its variables persist even though they should by default be confined to the scope of the script.
So far, the only way to clean this up that I've seen is to add a lot of
rv lines at the end of my scripts which will be unnecessary when the script is run normally within PowerShell. I've also got to remember to run
rv any time that I run a snippet of the script unless I actually want the variables to persist longer in the session.
Is there any way to configure PowerShell ISE to work more like an actual PowerShell console in this regard?