I have some questions regarding Microsoft Edge and PowerShell.
When two Edge Windows with different Window Titles are open, I would like to specify one window title in PowerShell and use Stop-Process to close the window with that window title. The ps1 file code with the expected specifications is below.
$WindowTitle = "test"
$EdgeProcesses = (Get-Process -Name msedge)
foreach ($process in $EdgeProcesses) {
$title = $process.MainWindowTitle
if ($title -eq $WindowTitle) {
$id = $process.Id
Stop-Process -Id $id
}
}
When windows with titles A and B are open, and when you use the above code to specify the window with the title A and Stop-Process, it will include not only the window with the title A, but also all Edge windows, including the window of title B. The same thing happens even if Edge is opened in app mode.
- Why does the above code behave like this?
- If you run the above code after activating the window with the last title Otsu in the above, the window will not close in the first place. Why is this.
市ノ瀬弘祐 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.