Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Powershell have a cache that needs to be cleared?

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

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 

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?

like image 775
dwwilson66 Avatar asked Jan 24 '13 13:01

dwwilson66


People also ask

Does PowerShell have a cache?

Or use the PowerShell Cache Editor – to modify and update the existing cache, which can be found via the Ribbon->File->Home->Platform->Edit Cache icon.

How do I clean up PowerShell?

In PowerShell, in order to clear the screen you can either type Clear-Host;, its aliases, cls; and clear; or its equivalent [System. Console]::Clear();.

How do I clear PowerShell command history?

Each PowerShell session has its own command history. To display the command history, use the Get-History cmdlet. By default, Clear-History deletes the entire command history from a PowerShell session. You can use parameters with Clear-History to delete selected commands.


1 Answers

I do not like the idea of having to close and re-open every time I need to clear the cache.

This works in PowerShell

Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host

like image 163
Patrick Avatar answered Nov 04 '22 12:11

Patrick