Sorry missed part of it...
$StartupVariables = ""
new-variable -force -name startupVariables -value ( Get-Variable | % { $_.Name
} )
function Cleanup-Variables
{
Get-Variable |
Where-Object { $startupVariables -notcontains $_.Name } |
% { Remove-Variable -Name "$($_.Name)" -Force -Scope "global" }
}
From: Dailey, Jeffrey C.
Sent: Friday, February 26, 2016 4:26 PM
To: '[email protected]' <[email protected]>
Subject: RE: clear session variables without closing the session?
This is what I use in my profile.ps1...
function Cleanup-Variables
{
Get-Variable |
Where-Object { $startupVariables -notcontains $_.Name } |
% { Remove-Variable -Name "$($_.Name)" -Force -Scope "global" }
}
Jeff Dailey
From: [email protected]<mailto:[email protected]>
[mailto:[email protected]] On Behalf Of Mote, Todd
Sent: Friday, February 26, 2016 4:16 PM
To: '[email protected]'
<[email protected]<mailto:[email protected]>>
Subject: [powershell] RE: clear session variables without closing the session?
It does, but it generates errors about the system variables and how they are
read-only. I really just want it to remove the ones defined by my UI and
script so that everything gets cleared out and I can start the form again as
though I had just opened it for the first time.
From: [email protected]<mailto:[email protected]>
[mailto:[email protected]] On Behalf Of Ward, Mike
Sent: Friday, February 26, 2016 3:13 PM
To: [email protected]<mailto:[email protected]>
Subject: [powershell] RE: clear session variables without closing the session?
I'm not sure if this is what you want, but I use 'Get-Variable |
Remove-Variable' - which removes all variables.
Mike
From: [email protected]<mailto:[email protected]>
[mailto:[email protected]] On Behalf Of Mote, Todd
Sent: Friday, February 26, 2016 12:42 PM
To: [email protected]<mailto:[email protected]>
Subject: [powershell] clear session variables without closing the session?
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