I'll come back and use $a or $a+=[something] after having used it hours,days
ago...
Is there a way to list/clear all variables in a running "session"? I
realize I can just exit and start, but is there something cooler I can run?
Marco
--
William Stacey [C# MVP]
"Marco Shaw" <ma...@Znbnet.nb.ca> wrote in message
news:ux4lm6zD...@TK2MSFTNGP04.phx.gbl...
Try "gci variable:" to list all PoSH variables. Unfortunately it doesn't
sort by name so I create a function for this I call vars:
function vars { get-variable | sort Name }
As William mentions, you can use Remove-Variable to eliminate variables.
The problem is nowing which you can remove and which you can't. Some will be
created with options that won't allow you to remove them (well at least
without using -force).
--
Keith
If you routinely use some prefix for your own variable names e.g. My
or XX then you could use
get-childitem variable:My* | remove-item -whatif
or similar to check what you would delete.
Remove the -whatif when you're comfortable that you will delete the
desried variables.
Andrew Watt MVP
On Thu, 23 Nov 2006 16:33:33 -0400, "Marco Shaw" <ma...@Znbnet.nb.ca>
wrote:
# remove some variables
Get-Variable * -Scope global | &{process{
if (!$_.Description -and !$_.Option -and !$_.Attributes) {
Remove-Variable $_.Name -Scope global -ErrorAction SilentlyContinue
}
}}
# up to you
$Error.Clear()
--
Thanks,
Roman
What I do is to start a new scope and do my experimentation. When I exit
that scope - all my temp variables get cleaned up.
I think immediately start a new session.
Now (put your seatbelt on for this one). If you ever wonder what your
temporary variables are, you just start ANOTHER nested scope and do the
following command:
Compare-Object (Get-Variable -scope 1) (get-Variable -Scope 0) -property
Name
Let me show you (I use the alias SANS for Start-NewScope):
PS> sans
Starting New Scope
PS> $x=55
PS> $y="test"
PS> sans
Starting New Scope
PS> Compare-Object (get-Variable -scope 1) (Get-Variable -scope 0) -property
name
name SideIndicator
---- -------------
x <=
y <=
Just to be clear about what is going on - Get-Object takes a -SCOPE
parameter. 0 means the current scope, 1 means the parent scope, 2 means the
grandparent etc. The reason you want to do a diff is that certain variables
get copied to a scope every time a new scope is created.
--
Jeffrey Snover [MSFT]
Windows PowerShell Architect
Microsoft Corporation
This posting is provided "AS IS" with no warranties, no confers rights.
vim.bat : Vim: Warnung: Die Ausgabe erfolgt nicht auf einem Terminal
At line:1 char:3
#translation:
#Warning: Output does not take place on a terminal
Any ideas?
--
greetings
dreeschkind
> Now (put your seatbelt on for this one). If you ever wonder what your
> temporary variables are, you just start ANOTHER nested scope and do the
> following command:
> Compare-Object (Get-Variable -scope 1) (get-Variable -Scope 0) -property
> Name
Wow, that's cool! But what the heck I'm doing wrong?
0:20 > $host.EnterNestedPrompt()
1:20 > $a=3
1:21 > Compare-Object (get-variable -scope 1) (get-variable -scope 0)
Get-Variable : Die Bereichsnummer "1" übersteigt die Anzahl der aktiven
Bereiche.
Parametername: scopeID
Der tatsächliche Wert war 1.
Bei Zeile:1 Zeichen:29
+ Compare-Object (get-variable <<<< -scope 1) (get-variable -scope 0)
-property Name
I can't access scope 1. Why?
tia
Max
As yes - the thing that creates the new scope is NOT
$host.EnterNestedPromp() - it is the FUNCTION (Start-NewScope) that contains
that line. That one bit me as well.
--
greetings
dreeschkind
> As yes - the thing that creates the new scope is NOT
> $host.EnterNestedPromp() - it is the FUNCTION (Start-NewScope) that
> contains that line.
Argh! Good point...
> That one bit me as well.
I'm glad to hear ;-)
Thanks,
Max