我可以获得当前打开的窗口的列表,如下所示:
获取进程|其中 {$_.mainWindowTitle} |格式表mainWindowTitle
如何编写正确的语法来循环并检查窗口名称是否存在然后退出?
以下是我想要执行的逻辑:
# BASIC-esque CONDITIONAL LOGIC
# FILENAME: CheckWindowName.ps1
Get-Process | where {$_.mainWindowTitle} | format-table mainWindowTitle
# LOOP START - Loop through $_.mainWindowTitle / mainWindowTitle
If $_.mainWindowTitle CONTAINS "*notepad*" Then
Exit #break script
Else
Echo "Hello World! There are no instances of notepad open"
End If
# LOOP END
最佳答案
Get-Process | where {$_.mainWindowTitle} | ForEach {
#iterates through processes here. each one can be referenced by $_
}
有关 ForEach-Object
工作原理的基本介绍可以在 TechNet 上找到。
关于powershell - 如果窗口名称存在,如何退出powershell脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29245728/