Get-ChildItem not finding my file

Hi all,
I am trying to use PS for searching for a file.

If I do this:

dir pwsh.exe /s

I finds the file, output like this:

> C:\Users\Matt>dir pwsh.exe /s
>  Volume in drive C has no label.
>  Volume Serial Number is 08CA-237C
> 
>  Directory of C:\Users\Matt\AppData\Local\Microsoft\WindowsApps
> 
> 08/13/2022  06:29 AM                 0 pwsh.exe
>                1 File(s)              0 bytes
> 
>  Directory of C:\Users\Matt\AppData\Local\Microsoft\WindowsApps\Microsoft.PowerShell_8wekyb3d8bbwe
> 
> 08/13/2022  06:29 AM                 0 pwsh.exe
>                1 File(s)              0 bytes
> 
>      Total Files Listed:
>                2 File(s)              0 bytes
>                0 Dir(s)  95,454,371,840 bytes free

It finds the files.

When I do this:

Get-ChildItem C:\ -Recurse | Where {$_.Name -match “pwsh.exe”}

It does not find it:

> PS C:\> Get-ChildItem C:\ -Recurse | Where {$_.Name -match "pwsh.exe"}
> Get-ChildItem: Access to the path 'C:\Program Files\Windows Defender Advanced Threat Protection\Classification\Configuration' is denied.
> Get-ChildItem: Access to the path 'C:\Program Files (x86)\Google\CrashReports' is denied.
> Get-ChildItem: Access to the path 'C:\Program Files (x86)\Google\Update\Install\{3514FE74-C32E-494B-AD28-064CF411C750}\CR_27118.tmp' is denied.
> Get-ChildItem: Access to the path 'C:\Users\postgres' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\appcompat\appraiser' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\appcompat\Programs' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\CSC' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\LiveKernelReports' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\Logs\SystemRestore' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\Minidump' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\ModemLogs' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\PLA\Reports' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\PLA\Rules' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\PLA\Templates' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\Prefetch' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\Provisioning\Autopilot' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\Resources\Themes\aero\VSCache' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\security\audit' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\security\cap' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\ServiceProfiles\LocalService' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\ServiceProfiles\NetworkService' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\ServiceState' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\Com\dmp' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\config' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\Configuration' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\drivers\DriverData' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\DriverState' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\HvsiSettingsProviders\Stage' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\ias' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\LogFiles\WMI' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\MsDtc' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\networklist' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\SleepStudy' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\spool\PRINTERS' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\spool\SERVERS' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\sru' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\Tasks' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\Tasks_Migrated' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\wbem\MOF' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\System32\WDI' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\SystemTemp' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\SysWOW64\Com\dmp' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\SysWOW64\config' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\SysWOW64\Configuration' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\SysWOW64\Msdtc' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\SysWOW64\NetworkList' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\SysWOW64\sru' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\SysWOW64\Tasks' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\Temp' is denied.
> Get-ChildItem: Access to the path 'C:\Windows\WUModels' is denied.

Any ideas why?

Thanks!

Because you’re doing it wrong. :wink:

Get-ChildItem -Path 'C:\Program Files' -Filter  'pwsh.exe' -Recurse -ErrorAction SilentlyContinue

BTW: When you post code you should format it as code - not as quote! :wink:

ok fixed the formatting.

hmm, This is not working for me:

PS7:

[ADMIN]: MK-1ST\Matt C:\> Get-ChildItem -Path 'C:\Program Files' -Filter  'pwsh.exe' -Recurse -ErrorAction SilentlyContinue
[ADMIN]: MK-1ST\Matt C:\> Get-ChildItem -Path 'C:\' -Filter  'pwsh.exe' -Recurse -ErrorAction SilentlyContinue
[ADMIN]: MK-1ST\Matt C:\>

PS5:

[ADMIN]: MK-1ST\Matt C:\> Get-ChildItem -Path 'C:\' -Filter  'pwsh.exe' -Recurse -ErrorAction SilentlyContinue
[ADMIN]: MK-1ST\Matt C:\>

Hmmm … how did you install PowerShell 7? :wink:

Try

Get-ChildItem -Path 'C:\' -Filter  'pwsh.exe' -Recurse -Force -ErrorAction SilentlyContinue

Thanks Olaf, interesting results.

I believe I installed PS7 with this:
PowerShell-7.2.5-win-x64.msi

But I also recall installing PS7 from the MS store, the metro version!

What’s interesting is from PS7, it finds 1 instance of the file then says cannot find path:

[ADMIN]: MK-1ST\Matt C:\> Get-PSVersion

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
7      2      6



[ADMIN]: MK-1ST\Matt C:\> Get-ChildItem -Path 'C:\' -Filter  'pwsh.exe' -Recurse -Force -ErrorAction SilentlyContinue

    Directory: C:\Program Files\WindowsApps\Microsoft.PowerShell_7.2.6.0_x64__8wekyb3d8bbwe

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           8/13/2022  6:29 AM         286608 pwsh.exe
Get-ChildItem: The system cannot find the path specified.

From PS5 it finds all 3 instances:

[ADMIN]: MK-1ST\Matt C:\> Get-ChildItem -Path 'C:\' -Filter  'pwsh.exe' -Recurse -Force -ErrorAction SilentlyContinue


    Directory: C:\Program Files\WindowsApps\Microsoft.PowerShell_7.2.6.0_x64__8wekyb3d8bbwe


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         8/13/2022   6:29 AM         286608 pwsh.exe


    Directory: C:\Users\Matt\AppData\Local\Microsoft\WindowsApps


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---l         8/13/2022   6:29 AM              0 pwsh.exe


    Directory: C:\Users\Matt\AppData\Local\Microsoft\WindowsApps\Microsoft.PowerShell_8wekyb3d8bbwe


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---l         8/13/2022   6:29 AM              0 pwsh.exe


[ADMIN]: MK-1ST\Matt C:\> Get-PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      22000  832

I guess it never hurts to -Force it!

Thanks,

-Matt

Well … I used to use the MSI installers as well and for me it looks like this:

 D:\sample
PS>Get-ChildItem -Path 'C:\Program Files' -Filter  'pwsh.exe' -Recurse -ErrorAction SilentlyContinue

    Directory: C:\Program Files\PowerShell\7

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---      Mi, 10.08.2022    19:05         286608 pwsh.exe

 Do, 15.Sept. 01:53:07   0002    00:00:02.1271896

The ones with the L in the Mode column are only links to the oriniginal one. :wink:

1 Like