PowerShell 删除变量

示例

要从内存中删除变量,可以使用Remove-Itemcmdlet。注意:变量名称不包含$。

Remove-Item Variable:\foo

Variable 有一个提供程序,允许大多数*项cmdlet像文件系统一样工作。

删除变量的另一种方法是使用Remove-Variable cmdlet及其别名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