我能得到这样的当前打开窗口的列表:如果窗口名称存在,如何退出powershell脚本?
Get-Process | where {$_.mainWindowTitle} | format-table 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
TKS,你能在'#iterates通过过程扩大这里。每一个都可以被$ _'逻辑引用? – Level1Coder 2015-03-25 01:26:56
请研究“PowerShell foreach循环”以了解更多信息。 现在,只需运行: if(ps notepad -ErrorAction SilentlyContinue){'Notepad is open'} – 2015-03-25 01:45:20