Removing a variable
suggest changeTo remove a variable from memory, one can use the Remove-Item cmdlet. Note: The variable name does NOT include the $.
Remove-Item Variable:\foo
The Variable: drive is a provider, so most *-Item cmdlets work on variables much as they do on files.
Remove-Variable (alias rv) removes a variable by name. Running either line below is enough. A second removal of the same name fails because the variable is already gone:
$var = "Some Variable" # Define variable 'var'
$var # Prints Some Variable
Remove-Variable -Name var
# or: rv var
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents