Powershell - Trying to exclude multiple directories, including C:\Program Files*

If you are experiencing problems with "Everything", post here for assistance.
Post Reply
wunderbar
Posts: 9
Joined: Wed Dec 17, 2025 8:59 pm

Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by wunderbar »

I am getting the results I expect when I run the following in Powershell:

Code: Select all

 es.exe *.ps1  !C:\ProgramData !C:\Users !C:\Windows\WinSxS !C:\Windows\diagnostics
However, when I try to add an exclusion for the

Code: Select all

C:\Program Files
folder(s), I get no output at all.

Code: Select all

 es.exe *.ps1  !C:\ProgramData !C:\Users !C:\Windows\WinSxS !C:\Windows\diagnostics !"C:\Program Files*\*"
It returns immediately, and there is no output.

When I include a wildcard where the space appears, I get the output I expect:

Code: Select all

 es.exe *.ps1  !C:\ProgramData !C:\Users !C:\Windows\WinSxS !C:\Windows\diagnostics !"C:\Program*Files*\*"

Code: Select all

C:\work\git.repos\MSCatalog\Utils\Build.ps1
C:\work\git.repos\MSCatalog\Utils\Deploy.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Public\Get-MSCatalogUpdate.ps1
C:\work\git.repos\MSCatalog\Tests\Get-MSCatalogUpdate.Tests.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Private\Get-UpdateLinks.ps1
C:\work\git.repos\PowerShell\scratch\go.ps1
C:\work\git.repos\PowerShell\scratch\go2.ps1
C:\work\git.repos\PowerShell\scratch\HarkLink.ps1
C:\Windows\System32\BestPractices\v1.0\Models\Microsoft\Windows\Hyper-V\Hyper-V.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Private\Invoke-CatalogRequest.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Private\Invoke-DownloadFile.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Private\Invoke-ParseDate.ps1
C:\work\git.repos\MSCatalog\Tests\Invoke-ParseDate.Tests.ps1
C:\work\git.repos\MSCatalog\Utils\Invoke-Tests.ps1
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.ODataUtils\Microsoft.PowerShell.ODataAdapter.ps1
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.ODataUtils\Microsoft.PowerShell.ODataAdapter.ps1
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.ODataUtils\Microsoft.PowerShell.ODataUtilsHelper.ps1
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.ODataUtils\Microsoft.PowerShell.ODataUtilsHelper.ps1
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.ODataUtils\Microsoft.PowerShell.ODataV4Adapter.ps1
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.ODataUtils\Microsoft.PowerShell.ODataV4Adapter.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Classes\MSCatalogResponse.Class.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Classes\MSCatalogUpdate.Class.ps1
C:\Windows\System32\WindowsPowerShell\v1.0\Examples\profile.ps1
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Examples\profile.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Public\Save-MSCatalogUpdate.ps1
C:\work\git.repos\MSCatalog\Tests\Save-MSCatalogUpdate.Tests.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Private\Set-TempSecurityProtocol.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Private\Sort-CatalogResults.ps1
So, hooray, I can get my work done.

But it really bothers me that I can't properly specify a "not path" on the command line. Specifying a "positive path" on the powershell command line works:

Code: Select all

PS Z:\WindowsISOs> es.exe *.ps1   "C:\Program Files*\*"
C:\Program Files\PostgreSQL\16\pgAdmin 4\python\Lib\site-packages\virtualenv\activation\powershell\activate.ps1
C:\Program Files (x86)\WindowsPowerShell\Modules\Pester\3.4.0\Examples\Calculator\Add-Numbers.ps1
C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Examples\Calculator\Add-Numbers.ps1
C:\Program Files (x86)\WindowsPowerShell\Modules\Pester\3.4.0\Examples\Calculator\Add-Numbers.Tests.ps1
C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Examples\Calculator\Add-Numbers.Tests.ps1
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\NuGet\Modules\NuGet\Add-WrapperMembers.ps1
C:\Program Files\Git\cmd\aslr-manager.ps1
C:\Program Files (x86)\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Assertions\Be.ps1
C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Assertions\Be.ps1
C:\Program Files (x86)\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Assertions\Be.Tests.ps1
C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Assertions\Be.Tests.ps1
C:\Program Files (x86)\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Assertions\BeGreaterThan.ps1
C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Assertions\BeGreaterThan.ps1
C:\Program Files (x86)\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Assertions\BeGreaterThan.Tests.ps1
C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Assertions\BeGreaterThan.Tests.ps1
C:\Program Files (x86)\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Assertions\BeLessThan.ps1
C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Assertions\BeLessThan.ps1
... yadda yadda...
But negating it results in zero output:

Code: Select all

PS Z:\WindowsISOs> es.exe *.ps1   !"C:\Program Files*\*"
PS Z:\WindowsISOs>
I have tried many permutations of adding backtick escapes ` so make sure the space character survives the parsing that happens on the command line, and a number of other things. But to no avail.

I suspect this is either a bug, or, much more likely, I'm missing something incredibly obvious.


I'm also getting confusing results I don't understand when I try to execute similar searches under cmd.exe
void
Developer
Posts: 19839
Joined: Fri Oct 16, 2009 11:31 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by void »

Powershell mangles the command line.

!"C:\Program Files\"
=>
"!C:\Program Files\"

(Puts the ! inside the quotes)

Please try the following:

Code: Select all

es.exe --% *.ps1  !C:\ProgramData !C:\Users !C:\Windows\WinSxS !C:\Windows\diagnostics !"C:\Program Files\"
--%
disables powershell parsing.



You can check the parameters received by ES in Everything in the debug console (Tools -> Debug -> Console)
wunderbar
Posts: 9
Joined: Wed Dec 17, 2025 8:59 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by wunderbar »

nuthin' :cry:

Code: Select all

PS Z:\WindowsISOs> es.exe --% *.ps1  !C:\ProgramData !C:\Users !C:\Windows\WinSxS !C:\Windows\diagnostics !"C:\Program Files\"
PS Z:\WindowsISOs>
I am aware of the stop-parsing token, but I neglected to mention that I tried it.

I just found that this issue exists:


Stop-parsing token is broken #18664

https://github.com/PowerShell/PowerShell/issues/18664

I have not fully read and understood what's going in that issue, however.
wunderbar
Posts: 9
Joined: Wed Dec 17, 2025 8:59 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by wunderbar »

You can check the parameters received by ES in Everything in the debug console (Tools -> Debug -> Console)
I will try this tonight. Thanks.
void
Developer
Posts: 19839
Joined: Fri Oct 16, 2009 11:31 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by void »

Please try:

Code: Select all

Start-Process es.exe -ArgumentList '*.ps1 !C:\ProgramData !C:\Users !C:\Windows\WinSxS !C:\Windows\diagnostics !"C:\Program Files\"' -NoNewWindow -Wait
wunderbar
Posts: 9
Joined: Wed Dec 17, 2025 8:59 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by wunderbar »

Working as expected.

Code: Select all

PS Z:\WindowsISOs> Start-Process es.exe -ArgumentList '*.ps1 !C:\ProgramData !C:\Users !C:\Windows\WinSxS !C:\Windows\diagnostics !"C:\Program Files\"   !"C:\Program Files (x86)\"' -NoNewWindow -Wait
C:\work\git.repos\MSCatalog\Utils\Build.ps1
C:\work\git.repos\MSCatalog\Utils\Deploy.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Public\Get-MSCatalogUpdate.ps1
C:\work\git.repos\MSCatalog\Tests\Get-MSCatalogUpdate.Tests.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Private\Get-UpdateLinks.ps1
C:\work\git.repos\PowerShell\scratch\go.ps1
C:\work\git.repos\PowerShell\scratch\go2.ps1
C:\work\git.repos\PowerShell\scratch\HarkLink.ps1
C:\Windows\System32\BestPractices\v1.0\Models\Microsoft\Windows\Hyper-V\Hyper-V.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Private\Invoke-CatalogRequest.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Private\Invoke-DownloadFile.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Private\Invoke-ParseDate.ps1
C:\work\git.repos\MSCatalog\Tests\Invoke-ParseDate.Tests.ps1
C:\work\git.repos\MSCatalog\Utils\Invoke-Tests.ps1
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.ODataUtils\Microsoft.PowerShell.ODataAdapter.ps1
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.ODataUtils\Microsoft.PowerShell.ODataAdapter.ps1
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.ODataUtils\Microsoft.PowerShell.ODataUtilsHelper.ps1
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.ODataUtils\Microsoft.PowerShell.ODataUtilsHelper.ps1
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.ODataUtils\Microsoft.PowerShell.ODataV4Adapter.ps1
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.ODataUtils\Microsoft.PowerShell.ODataV4Adapter.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Classes\MSCatalogResponse.Class.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Classes\MSCatalogUpdate.Class.ps1
C:\Windows\System32\WindowsPowerShell\v1.0\Examples\profile.ps1
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Examples\profile.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Public\Save-MSCatalogUpdate.ps1
C:\work\git.repos\MSCatalog\Tests\Save-MSCatalogUpdate.Tests.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Private\Set-TempSecurityProtocol.ps1
C:\work\git.repos\MSCatalog\MSCatalog\Private\Sort-CatalogResults.ps1
PS Z:\WindowsISOs>
I should have known to try Start-Process

Also: I do not see anything about Debug in the tools menu?
Last edited by wunderbar on Wed Dec 17, 2025 11:53 pm, edited 1 time in total.
void
Developer
Posts: 19839
Joined: Fri Oct 16, 2009 11:31 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by void »

Please also exclude C:\Program Files (x86):

Code: Select all

Start-Process es.exe -ArgumentList '*.ps1 !C:\ProgramData !C:\Users !C:\Windows\WinSxS !C:\Windows\diagnostics !"C:\Program Files\" !"C:\Program Files (x86)\"' 
-NoNewWindow -Wait
-or-

Code: Select all

Start-Process es.exe -ArgumentList '*.ps1 !C:\ProgramData !C:\Users !C:\Windows\WinSxS !C:\Windows\diagnostics !"C:\Program Files"'
-NoNewWindow -Wait


To show the debug console in Everything 1.4:
Copy and paste the following into your Everything search box:
/debug

Press ENTER in your Everything search box.

To hide the debug console in Everything 1.4:
Copy and paste the following into your Everything search box:
/debug

Press ENTER in your Everything search box.
wunderbar
Posts: 9
Joined: Wed Dec 17, 2025 8:59 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by wunderbar »

Please also exclude C:\Program Files (x86):
lol, yes, I forgot. It's working now, and I updated that post.
Copy and paste the following into your Everything search box:
/debug
That debug window is absolutely lovely. Are you using named pipes for inter-process communication?
void
Developer
Posts: 19839
Joined: Fri Oct 16, 2009 11:31 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by void »

Everything 1.4 uses WM_COPYDATA
Everything 1.5 uses named pipes.
matandra
Posts: 8
Joined: Tue Dec 16, 2025 2:19 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by matandra »

Starting with PowerShell 7.3 (I think) you can get around this parsing stuff by setting
$PSNativeCommandArgumentPassing to "legacy" together with the stop-parsing-token:

Code: Select all

$PSNativeCommandArgumentPassing="legacy"
es --% c: *.ps1 !"c:\Program files" !c:\Windows
More info can be found at the microsoft site
void
Developer
Posts: 19839
Joined: Fri Oct 16, 2009 11:31 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by void »

Thank you for the information matandra,

I'm going to add a
--argv
option to es that supports the $PSNativeCommandArgumentPassing="windows" mode.

When
--argv
is used, ES will use a CommandLineToArgv mode.
aka $PSNativeCommandArgumentPassing="windows" mode.

when added, this will support:

Code: Select all

es -argv --% c: *.ps1 !"c:\Program files" !c:\Windows
es -argv 'c: *.ps1 !"c:\Program files" !c:\Windows'
es -argv "c: *.ps1 !`"c:\Program files`" !c:\Windows"
-argv
will avoid changing PSNativeCommandArgumentPassing.



I will also consider checking the calling process for powershell 7 and use --argv by default.
I will not use --argv by default from a command prompt as it breaks trailing slashes in quotes. -It's one of the main reasons I don't use CommandLineToArgv.
matandra
Posts: 8
Joined: Tue Dec 16, 2025 2:19 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by matandra »

Ok, using this dummy -argv is clever. Special characters like ';', '>','<','|' will still need escaping, but this is ok because the user should be aware in which shell he is working.

Presumably you are parsing the content of GetCommandLineW(). I have noticed an annoying behavior: an argument !"a b" is converted to "!a b".
The PEB (via NtQueryInformationProcess()) holds the unmodified command line. I don't know if you want to go that far down.
void
Developer
Posts: 19839
Joined: Fri Oct 16, 2009 11:31 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by void »

ES will normally parse the command line itself using GetCommandLineW()

It is Powershell that converts !"a b" to "!a b"
void
Developer
Posts: 19839
Joined: Fri Oct 16, 2009 11:31 pm

Re: Powershell - Trying to exclude multiple directories, including C:\Program Files*

Post by void »

es 1.1.0.37 adds the -argv command line option to use CommandLineToArgvW.

Please use -argv as the first parameter when calling ES from powershell 7.

For example:

es -argv --% !"C:\Program Files\"
Post Reply