【发布时间】:2016-06-02 15:34:08
【问题描述】:
您好,我在 Powershell 中遇到了一个问题,即执行直到条件为真,但循环不会停止。如果我将 -eq 更改为 0。它将停止......基本上这应该做的是获取文本文件中的计算机数量。将该数字存储在 $count 中。然后为列表中的每台计算机重新启动服务,直到到达最后一台。
$computers = gc C:\temp\computers.txt
$count = $computers.count
Do {
foreach($computer in $computers){
$readCount = $computer.ReadCount
gwmi win32_service -ComputerName $computer | where {$_.name -like "*was*"} | Restart-Service
}
}
Until (($count - $readCount) -eq 1)
【问题讨论】:
-
您遍历
foreach循环内的所有计算机,并且仅在迭代完成后检查Until条件。由于ReadCount属性基于一,$readCount将等于$count,因此您的Until条件永远不会满足。
标签: powershell do-loops