Caching Powershell是否有需要清除的缓存?

Caching Powershell是否有需要清除的缓存?,caching,powershell,Caching,Powershell,今天早上,我将一个目录从本地网络驱动器复制到临时文件夹进行测试。这个错误出现了 Get-Content : Cannot find path 'C:\users\xxxxx\desktop\cgc\Automatic_Post-Call_Survey_-_BC,_CC.txt' because it does no t exist. At C:\users\xxxxx\desktop\cgc\testcountexcl1.ps1:55 char:12 + Get-Content <<

今天早上,我将一个目录从本地网络驱动器复制到临时文件夹进行测试。这个错误出现了

Get-Content : Cannot find path 'C:\users\xxxxx\desktop\cgc\Automatic_Post-Call_Survey_-_BC,_CC.txt' because it does no
t exist.
At C:\users\xxxxx\desktop\cgc\testcountexcl1.ps1:55 char:12
+ Get-Content <<<<  $txtfile | Get-WordCount -Exclude (Get-Content c:\temp\exclude.txt) | select -First 15
    + CategoryInfo          : ObjectNotFound: (C:\users\xxxxx...ey_-_BC,_CC.txt:String) [Get-Content], ItemNotFoundEx
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
Get Content:找不到路径“C:\users\xxxxx\desktop\cgc\Automatic\u Post-Call\u Survey\u-\u BC,\u CC.txt”,因为它没有
不存在。
在C:\users\xxxxx\desktop\cgc\testcountexc1.ps1:55 char:12

+Get Content变量存储在会话中,因此如果关闭powershell控制台并打开新控制台,所有自定义变量都将消失。如果要查看存在哪些变量,请使用
Get Variable
。要删除特定变量(确保它已消失),可以使用:

删除变量varname


至于你的问题。全局(会话)作用域中的变量将存储在会话中,直到将其删除或覆盖。如果您使用同一个powershell控制台运行该代码两次,则
$inpath
应在第二次设置为
“C:\temp\tx”
,并且
$srcfiles
将使用新的文件列表进行更新。

我不喜欢每次需要清除缓存时都必须关闭并重新打开的想法

这在PowerShell中有效

删除变量*-ErrorAction SilentlyContinue;移除模块*$error.Clear();清除主机

除此之外,您还可以删除如下指定模块:

,@("MyModule1","MyModule2") | %{&remove-module -erroraction:silentlycontinue $_}
灵感来源于


因此,Patrick的一行将变成
Remove Variable*-ErrorAction SilentlyContinue@(“MyModule1”、“MyModule2”)|%{&Remove模块-ErrorAction:SilentlyContinue$|$error.Clear();清除主机

您确定两次都运行了整个代码吗?设置
$inpath
$srcfiles
的行都是用新值第二次执行的吗?它们是用新值执行的,但其行为就像传递了旧值一样。Remove-Module*没有太大帮助。它应该跟在导入模块后面,否则很明显,这就是我想要的答案。我已经将这一行放在了脚本的顶部,现在我不必每次都重新/打开PS ISE。
,@("MyModule1","MyModule2") | %{&remove-module -erroraction:silentlycontinue $_}