Powershell是否有需要清除的缓存? [英] Does Powershell have a cache that needs to be cleared?

查看:441
本文介绍了Powershell是否有需要清除的缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天早上,我将本地网络驱动器中的目录复制到temp文件夹中进行测试。出现此错误。

This morning, I copied a directory from my local, networked drive to temp folder for testing. This error appeared.

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

此举是可以预期的。 ..PS找不到引用的路径...但是我在运行脚本之前做了以下更改(旧注释在新注释上方):

This would be expected with the move...PS can't find the path referenced...but I made the following change prior to running the script (old commented out above the new):

$input = Get-Content c:\temp\wordCount.txt
<# $inpath = "C:\users\xxxxx\desktop\cgc\tx"    #>
$inpath = "C:\temp\tx"  
$srcfiles = Get-ChildItem $inpath -filter "*.txt"    
$notPermittedWords = Get-Content c:\temp\exclude.txt 

我的第一个建议是,某种缓存保存了我的<$ c我上次运行的$ c> $ inpath 变量...但是无法确定这是否是预期的PowerShell行为。我是在误解错误还是解决方案?我该如何刷新缓存或将任何变量存储在内存中?

My first inkling is that there's some kind of cache holding my $inpath variable from my last run...but have not been able to find out if that's expected PowerShell behavior. Am I misinterpreting the error or the solution? How do I flush the cache or whatever varables may be stored in memory?

推荐答案

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

Variables are stored in the session, so if you close your powershell console and open a new one, all custom variables will be gone. If you want to see what variables exists, use Get-Variable . To delete a specific variable(to make sure it's gone), you could use:

Remove-Variable变量名

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

As for you question. A variable in the global(session) scope is stored in the session until it's removed or overwritten. If you used the same powershell console to run that code twice, then $inpath should have been set to "C:\temp\tx" the second time, and $srcfiles would be updated with the new filelist.

这篇关于Powershell是否有需要清除的缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆