Powershell 是否有方法引用管道中的上一个对象?
在下面的代码中,是否有某种方法可以从第三段引用第二段中的当前对象Powershell 是否有方法引用管道中的上一个对象?,powershell,powershell-2.0,Powershell,Powershell 2.0,在下面的代码中,是否有某种方法可以从第三段引用第二段中的当前对象 `$a = "one", "two", "three"` `$a | % {$_ -replace "t","x" } | % { $_ }` 为了有点不同的解释,我希望能够在第三个管道段中使用类似于|%{“$.$.$:$.}的内容来获得以下输出: one: one two: xwo three: xhree 这是迄今为止我找到的唯一解决办法。有更好的选择吗 $a = "one", "two", "three" $a | %
`$a = "one", "two", "three"`
`$a | % {$_ -replace "t","x" } | % { $_ }`
为了有点不同的解释,我希望能够在第三个管道段中使用类似于|%{“$.$.$:$.}
的内容来获得以下输出:
one: one
two: xwo
three: xhree
这是迄今为止我找到的唯一解决办法。有更好的选择吗
$a = "one", "two", "three"
$a | % { $i = $_; $_ -replace "t","x" } | % { "$i : $_" }
输出:
one : one
two : xwo
three : xhree
$a |%{“$\:$($)-替换“t”,“x”)”}
它没有我想要的那么漂亮,但它是一个可行的解决方案。谢谢。我的最终解决方案是这样的:$a |%{“$\:$”(
“Hello$\uworld”){$\ureplace
“t”,
“t”)}
我想下次只使用嵌套的foreach循环。:)$a |%{“$\:$(“Hello$\uworld”-replace“t”,“t”)“}在我的情况下,我实际上没有执行-replace
,因此我必须通过另一个cmdlet发送对象。我想我选择了一个糟糕的例子来证明我的问题!