简体   繁体   English

Get-ChildItem未显示文件夹中的所有文件

[英]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. 当我在PowerShell中调用Get-ChildItem时 ,它仅返回目录中存在的一些文件。 This is the driver folder, so I tried using the -Force parameter in case they were hidden, but with no luck. 这是驱动程序文件夹,因此我尝试使用-Force参数以防万一它们被隐藏但没有运气。

It's interesting though because it works perfect on my Windows 7 32 bit, but not 64 bit. 不过,这很有趣,因为它可以在我的Windows 7 32位(而不是64位)上完美运行。 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. 我相信PowerShell会向您显示所有内容,但是您在x86 PowerShell提示符下查看的文件夹并不是您所想的。 The directory you're actually looking at is under C:\\Windows\\SysWow64\\Drivers and not actually C:\\Windows\\System32\\Drivers. 您实际查看的目录位于C:\\ Windows \\ SysWow64 \\ Drivers下,而不是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 ). 这是由于Windows功能(Vista及更高版本)针对在64位操作系统上运行的32位进程(称为虚拟化)(特别是文件系统重定向器 )所致。 When you run a 64-bit PowerShell prompt virtualization is not used so you see the real C:\\Windows\\System32\\Drives dir. 当您运行64位PowerShell提示时,未使用虚拟化,因此您会看到真实的C:\\ Windows \\ System32 \\ Drives目录。

From a 32-bit PowerShell prompt, you can see the "real" C:\\windows\\system32\\drivers dir by using this path: 在32位PowerShell提示符下,可以使用以下路径查看“真实的” C:\\ windows \\ system32 \\ drivers目录:

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.) (当然,如果您想了解更详细的用法,则需要使用for循环之类的方法。)

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 至于包含哪些文件,默认情况下不会显示隐藏文件和系统文件: https : //docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-6

  • Hidden parameter: Hidden files only Hidden参数:仅隐藏文件
  • System parameter: System files only System参数:仅系统文件
  • Force parameter: Include hidden and system files, with regular files Force参数:包括隐藏文件和系统文件,以及常规文件

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). 我比较了从PowerShell报告的大小(在授予权限之前)和在文件资源管理器中报告的大小(在授予权限之后)。 Size and count was the same. 大小和数量相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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