This seems to work from the console. Some tweaking would be necessary to work
from ISE or whatever interpreter you’re using.
$AllVariables = (Get-Variable).Name
$DefaultVariables = (powershell {Get-Variable}).Name
$ComparedVariables = Compare-Object $AllVariables $DefaultVariables
foreach ($ComparedVariable in $ComparedVariables) {
Remove-Variable $ComparedVariable.InputObject
}
Remove-Variable ComparedVariable
Remove-Variable ComparedVariables
From: [email protected] [mailto:[email protected]] On
Behalf Of Mote, Todd
Sent: Friday, February 26, 2016 2:54 PM
To: '[email protected]' <[email protected]>
Subject: RE: [powershell] clear session variables without closing the session?
I designed this UI for others to use and made a reset button to clear all the
text boxes and pull downs to get it ready to go again, so while I don’t mind to
run it in a new session every time, I was looking for something the reset
button could do from my UI to clean things up?
From: [email protected]<mailto:[email protected]>
[mailto:[email protected]] On Behalf Of Ryan
Sent: Friday, February 26, 2016 2:48 PM
To: [email protected]<mailto:[email protected]>
Subject: Re: [powershell] clear session variables without closing the session?
I use my extension to run PowerShell scripts in a new session:
http://www.ephingadmin.com/run-wpf-powershell-scripts-in-the-ise-without-all-the-crashing/
It basically saves what you have in the console (either saving the script or
saving the unsaved script to a temp file) and then runs that file in a new
session outside of the ISE. I wrote this for WPF writing since the ISE crashes
every now and then when editing WPF scripts.
On Fri, Feb 26, 2016 at 2:45 PM Mote, Todd
<[email protected]<mailto:[email protected]>> wrote:
Is there an easy or clever way to clear all of the user defined variables I
define without having to close my UI, or list each of them explicitly for
remove-variable? I have a reset button in my UI to clear everything out for
the next run of this process, but it seems like there’s always something left
behind that screws something up on a subsequent run.
Todd
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1