Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 是否有方法引用管道中的上一个对象?_Powershell_Powershell 2.0 - Fatal编程技术网

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发送对象。我想我选择了一个糟糕的例子来证明我的问题!