Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
powershell如何一次清除所有变量的变量缓存_Powershell - Fatal编程技术网

powershell如何一次清除所有变量的变量缓存

powershell如何一次清除所有变量的变量缓存,powershell,Powershell,我使用“删除变量名”清除powershell脚本中的变量缓存。我想知道是否有cmd可以一次性清除脚本中所有变量的变量缓存。您可以使用:删除项目变量:*-force,我猜。您可以在脚本顶部或配置文件中添加此命令: $sysvars = get-variable | select -ExpandProperty name $sysvars += 'sysvar' 然后在结束时这样做: get-variable * | where { $_.name -notin $sysvars } | R

我使用“删除变量名”清除powershell脚本中的变量缓存。我想知道是否有cmd可以一次性清除脚本中所有变量的变量缓存。

您可以使用:
删除项目变量:*-force,我猜。

您可以在脚本顶部或配置文件中添加此命令:

$sysvars = get-variable | select -ExpandProperty name
$sysvars += 'sysvar'
然后在结束时这样做:

get-variable * |
 where { $_.name  -notin $sysvars } |
 Remove-Variable
您也可以这样做:

 get-variable -Scope script | remove-variable

但是,如果您在ISE中工作,它可能会删除您不打算执行的变量。

请小心,显然在某些情况下,您可以通过过于热心的变量清除来吞咽一些东西: