直到循环条件遇到 - 但循环继续 - Powershell

时间:2016-06-02 06:58:15

标签: powershell do-loops

嗨我在PowerShell中遇到了问题,其中Do Until条件为真,但循环不会停止。如果我将-eq更改为0.它将停止...基本上应该做的是获取文本文件中的计算机数量。将该数字存储在$ count中。然后重新启动列表中每台计算机的服务,直到它到达最后一台计算机。

let tabBar = self.storyboard!.instantiateViewControllerWithIdentifier("tabBarViewController") as! UITabBarController tabBarVC.selectedIndex = 0
self.navigationController?.pushViewController(tabBar, animated: true)

1 个答案:

答案 0 :(得分:0)

您不需要Do-Until循环,因为您可以遍历计算机。要跳过上一台计算机,请使用带有-SkipLast 1参数的Select-Object cmdlet:

Get-Content 'C:\temp\computers.txt' | Select-Object -SkipLast 1 | Forach-Object {
    gwmi win32_service -ComputerName $computer | 
        where {$_.name -like "*was*"} | 
        Restart-Service
}
相关问题