我不确定是否有更高效的方法可以做到这一点,或者如果组合一段时间,for循环甚至可以工作,但我怎样才能解决这个问题,只有当for循环中的每个项目都返回时才能运行该函数真正?如何设置do-while(for())循环?
$In = @()
While ($In[-1] -ne 'done') {$In += @(Read-Host 'Prompt')}
do {
for($i=0;$i-le $In.length-2;$i++) {function($In[$i])}
}
while (for($j=0;$j-le $In.length-2;$j++)
{Get-Service ($In[$j]) | $_.status} -eq "Running")
以$在各种服务名称的数组,该做的-while应该在服务中的任何一个返回“已停止”状态重新启动阵列中的每个服务。
这非常复杂。这应该是做什么? – 2013-03-07 07:11:49
对不起,我试图摆脱不必要的信息。 – Forager 2013-03-07 07:28:18
考虑到你的意图,我会做'a','b','c'| ? {(Get-Service -name $ _)。Status -eq'Stopped'} |重启Service' – 2013-03-07 07:37:55