gi c:\temp\csproj\test.csproj | % { (gc $_.fullname) -replace
'HAHAHA','abc' | sc $_.fullname }
I used it to replace some text in file. However after second look I
don't know how it is possible that it works -- the problem is in the
last cmdlet:
How is it possible that $_ has property FullName? I thought that the %
(foreach-object) takes its pipeline input, modifies it (so from object
sent by gi creates array of lines produced by -replace operator) and
sends as input to set-content. So pipeline input for sc should be
array of strings - content from the file. There should be no fullName
property at all.
It seems that the $_ variable points to some 'outer pipeline scope'.
Even
Trace-Command -Name ParameterBinding -pshost -exp { gi c:\temp\csproj
\test.csproj | % { (gc $_.fullname) -replace 'HAHAHA','abc' | sc
$_.fullname } }
doesn't help me.
There is
DEBUG: ParameterBinding Information: 0 : BIND arg [C:\temp\csproj
\test.csproj] to parameter [Path]
but I don't know where it takes the value C:\temp\csproj\test.csproj
GI (Get-Item) just takes file object and do not transform this object to
anything. Just test this:
gi c:\temp\csproj\test.csproj | fl *
you will see file object and it will sent to pipeline.
--
WBR, Vadims Podans
MVP: PowerShell
PowerShell blog - www.sysadmins.lv
"stej" <cerna...@seznam.cz> rakstija zinojuma
"news:7be641f0-67ba-40f0...@r5g2000yqb.googlegroups.com"...
(Unfortunatelly I can not currently create some Posh tests.]
Nested pipeline don't replace $_ variable, because this variable is outside
of pipeline scriptoblock. See these examples:
gi c:\temp\csproj\test.csproj | % { (gc $_.fullname) -replace
'HAHAHA','abc' | sc $_.fullname }
and:
gi c:\temp\csproj\test.csproj | % { (gc $_.fullname) -replace
'HAHAHA','abc' | sc {$_.fullname} }
in second example I put $_.fullname in scriptoblock. In this case
set-content will try to find FullName property from -replace operator
output. In your case $_ variable is not set in scriptoblock.
--
WBR, Vadims Podans
MVP: PowerShell
PowerShell blog - www.sysadmins.lv
"stej" <cerna...@seznam.cz> rakstija zinojuma
"news:e3995b3d-4d67-4395...@r24g2000yqd.googlegroups.com"...
Do you have any resource for this topic?
On Jan 15, 2:52 pm, "Vadims Podans [MVP]" <vpodans> wrote:
> oh, sorry, I missed this point.
>
> Nested pipeline don't replace $_ variable, because this variable is outside
> of pipeline scriptoblock. See these examples:
> gi c:\temp\csproj\test.csproj | % { (gc $_.fullname) -replace
> 'HAHAHA','abc' | sc $_.fullname }
>
> and:
> gi c:\temp\csproj\test.csproj | % { (gc $_.fullname) -replace
> 'HAHAHA','abc' | sc {$_.fullname} }
>
> in second example I put $_.fullname in scriptoblock. In this case
> set-content will try to find FullName property from -replace operator
> output. In your case $_ variable is not set in scriptoblock.
> --
> WBR, Vadims Podans
> MVP: PowerShell
> PowerShell blog -www.sysadmins.lv
>
> "stej" <cerna.ze...@seznam.cz> rakstija zinojuma
-Paul
On Jan 16, 4:27 am, PaulChavez <PaulCha...@discussions.microsoft.com>
wrote:
>> The input to Set-Content *is* a bunch of strings, but the positional path
>> parameter to set content, with the value $_.fullname, is still in scope
>> of
>> the foreach scriptblock and so references the FileInfo object from your
>> initial get-childitem command.
>Thank you for your responses. I summed it up here:
>http://www.leporelo.eu/blog.aspx?id=learned-again-something-about-powershell-pipelines
To paraphrase your web page's opening line, I think we're all learning
something from the postings here, and not just in this thread. A tip o' the
hat (am I dating myself?) to the entire newsgroup and especially to the
PowerShell gurus who take the time to provide mini-tutorials to the rest of
us.
Joe Morris
"stej" <cerna...@seznam.cz> rakstija zinojuma
"news:595b316d-3ae5-4716...@u6g2000yqf.googlegroups.com"...