Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

GCI and Get-content not work on the same place why?

$
0
0

If I put *.ps1 file in the same place as the files the files is change :-)

gciC:\loc*.txt-recurse|ForEach{

  (

Get-Content$_|ForEach{$_-replace"Lars","Ole"})|Set-Content$_

}

But I put *.ps1 it somewhere else on the disk then says the get-content

 Get-Content : Cannot find path 'C:\peter.txt' because it does not exist.

At C:\work\nr1.ps1:3 char:4

+   (Get-Content $_ | ForEach {$_ -replace "Lars", "Ole"}) | Set-Content $_

+    ~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (C:\peter.txt:String) [Get-Content], ItemNotFoundException

    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

But it has found the file peter.txt ?

Why work Get-Content not the same place as gci


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>