Closing All Explorer Windows in PowerShell

浪尽此生 提交于 2019-12-06 04:19:15

问题


I am writing the following code to close all explorer windows with PowerShell:

(New-Object -comObject Shell.Application).Windows() |
 ? { $_.FullName -ne $null} |
 ? { $_.FullName.toLower().Endswith('\explorer.exe') } | % { $_.Quit() }

But it does not close out all the open windows. Instead, it closes only RoundDown(N/2)+1 windows, and leaves RoundUp(N/2)-1 windows open.

Can anyone help with this?


回答1:


I think there's something in the pipeline that goes wrong. This code works:

$a = (New-Object -comObject Shell.Application).Windows() |
 ? { $_.FullName -ne $null} |
 ? { $_.FullName.toLower().Endswith('\explorer.exe') } 

 $a | % {  $_.Quit() }


来源:https://stackoverflow.com/questions/17754230/closing-all-explorer-windows-in-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!