PowerShell Variables in PowerShell Removing a variable


Example

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

Variable has a provider to allow most *-item cmdlets to work much like file systems.

Another method to remove variable is to use Remove-Variable cmdlet and its alias rv

$var = "Some Variable" #Define variable 'var' containing the string 'Some Variable'
$var #For test and show string 'Some Variable' on the console

Remove-Variable -Name var
$var 

#also can use alias 'rv'
rv var