# Get-ChildItem not finding my file

**URL:** <https://forums.powershell.org/t/get-childitem-not-finding-my-file/20422>\
**Category:** PowerShell Help\
**Created:** [September 14, 2022, 11:08pm UTC](https://forums.powershell.org/t/get-childitem-not-finding-my-file/20422 "2022-09-14T23:08:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt1974](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@matt1974](https://forums.powershell.org/u/matt1974)\
**Post date:** [September 14, 2022, 11:08pm UTC](https://forums.powershell.org/t/get-childitem-not-finding-my-file/20422/1 "2022-09-14T23:08:16Z")

</div>

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:

```auto
> 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:

```auto
> 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!

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 14, 2022, 11:19pm UTC](https://forums.powershell.org/t/get-childitem-not-finding-my-file/20422/2 "2022-09-14T23:19:13Z")

</div>

> [@matt1974](#):
>
> Any ideas why?

Because you’re doing it wrong. 😉

```auto
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! 😉

---

<div class="post-metadata">

**Author:** ![matt1974](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@matt1974](https://forums.powershell.org/u/matt1974)\
**Post date:** [September 14, 2022, 11:36pm UTC](https://forums.powershell.org/t/get-childitem-not-finding-my-file/20422/3 "2022-09-14T23:36:51Z")

</div>

ok fixed the formatting.

hmm, This is not working for me:

PS7:

```auto
[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:

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

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 14, 2022, 11:42pm UTC](https://forums.powershell.org/t/get-childitem-not-finding-my-file/20422/4 "2022-09-14T23:42:00Z")

</div>

> [@matt1974](#):
>
> hmm, This is not working for me:

Hmmm … how did you install PowerShell 7? 😉

Try

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

```

---

<div class="post-metadata">

**Author:** ![matt1974](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@matt1974](https://forums.powershell.org/u/matt1974)\
**Post date:** [September 14, 2022, 11:50pm UTC](https://forums.powershell.org/t/get-childitem-not-finding-my-file/20422/5 "2022-09-14T23:50:39Z")

</div>

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:

```auto
[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:

```auto
[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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 14, 2022, 11:58pm UTC](https://forums.powershell.org/t/get-childitem-not-finding-my-file/20422/6 "2022-09-14T23:58:26Z")

</div>

> [@matt1974](#):
>
> I believe I installed PS7 with this:  
> PowerShell-7.2.5-win-x64.msi

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

```auto
 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

```

> [@matt1974](#):
>
> From PS5 it finds all 3 instances:

The ones with the `L` in the `Mode` column are only links to the oriniginal one. 😉

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/get-childitem-not-finding-my-file/20422/7 "2024-05-16T20:16:37Z")

</div>

Closed on May 16, 2024, 8:16pm UTC


