Removing a variable

suggest change

To 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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents