Closing all Windows Explorer in PowerShell

I am writing the following code to close all browser windows using PowerShell:

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

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

Can anyone help with this?

+4
source share
1 answer

I think something in the pipeline is going wrong. This code works:

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

Source: https://habr.com/ru/post/1492380/


All Articles