我成批调用powershell并用双引号将powershell命令如下:
Powershell -commands "&{...}"
在powershell命令中,我有一个$ counter = 0,它在for循环中更改(例如3)。现在我想在屏幕上回显“找到3个对象”。
我已经尝试了一些在线提到的方法,但是没有一个对我有用。可能是因为我已经使用过“”来引用powershell命令,所以我只能在其中使用''。
我试过了
echo(write-output) $counter objects found
echo '$counter objects found'
echo '$($counter) objects found'
$counter='0' echo '$counter objects found'
我希望看到
3 objects found
但我明白了
3
objects
found #or
$counter objects found #or
$($counter) objects found
另一种方法是将$ counter的值传递回批处理,但我认为在powershell中执行回显会更容易。有人可以帮忙吗?提前致谢。
我试过了
$counter = 0
echo(write-host -NoNewline) "$counter objects found"
我得到了
找到0个物件
在之后添加参数write-host
。希望我能帮到你!
编辑:
powershell -NoP -C "$Counter=0;1..3|%{$Counter++};'{0} objects found' -f $Counter"
批量为我工作,@ LotPings发布
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句