简体   繁体   中英

Get-ChildItem is not showing all files in a folder

When I call Get-ChildItem in PowerShell it is only returning a few of the files that exist in the directory. This is the driver folder, so I tried using the -Force parameter in case they were hidden, but with no luck.

It's interesting though because it works perfect on my Windows 7 32 bit, but not 64 bit. Any ideas?

I believe PowerShell is showing you everything however the folder you're looking at in the x86 PowerShell prompt isn't what you think. The directory you're actually looking at is under C:\\Windows\\SysWow64\\Drivers and not actually C:\\Windows\\System32\\Drivers. This is due to a Windows feature (Vista and higher) for 32-bit processes running on 64-bit OS called virtualization (specifically the File System Redirector ). When you run a 64-bit PowerShell prompt virtualization is not used so you see the real C:\\Windows\\System32\\Drives dir.

From a 32-bit PowerShell prompt, you can see the "real" C:\\windows\\system32\\drivers dir by using this path:

Get-ChildItem C:\\Windows\\SysNative\\Drivers

I ran across this while searching for a similar issue. I want to list user folder usage, but run into issues with folder ownership/permissions. Even though I am a local admin, I need to explicitly give myself access. Not ideal. Below gives accurate usage, despite permissions. (Of course, if you want to know more detailed usage, you need to use a for loop or something.)

Get-ChildItem "C:\Users" -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object Length -Sum

As for what files are included, hidden and system files are not shown by default: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-6

  • Hidden parameter: Hidden files only
  • System parameter: System files only
  • Force parameter: Include hidden and system files, with regular files

To confirm, I granted myself permission to one of the user directories. I compared size reported from PowerShell (before granting permission) and that reported in File Explorer (after granting permission). Size and count was the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM