如何使用PowerShell以递归方式搜索目录中的所有文件,包括隐藏目录中的隐藏文件?

chr*_*ips 2 powershell search

要递归搜索隐藏文件,我使用:

gci -Path C:\ -Filter part_of_filename* -Recurse -Force | where { $_.Attributes -match "Hidden"}
Run Code Online (Sandbox Code Playgroud)

输出显示了许多与此完全相同的错误(取决于路径):

Get-ChildItem:拒绝访问路径"C:\ Documents and Settings".在C:\ Users\USERNAME\Documents\powershell\searchdisk.ps1:10 char:5 + gci <<<< -Path C:\ -Filter part_of_filename*-Recurse -Force | 其中{$ _.Attributes -match"Hidden"} + CategoryInfo:PermissionDenied:(C:\ Documents and Settings:String)[Get-ChildItem],UnauthorizedAccessException + FullyQualifiedErrorId:DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

我需要一个PowerShell命令,以递归方式搜索包含隐藏目录的任何目录,并向我显示所有文件,包括名称为part_of_filename*的隐藏文件(对于此示例)

我使用PowerShell ISE作为管理员运行命令.它不会搜索内部目录

C:\ WINDOWS\SYSTEM32\LogFiles文件\ WMI\RtBackup

evi*_*obu 7

你说得对.只需在高架控制台中运行它并移除过滤器即可.如果您不关心权限错误,请附加-ErrorAction SilentlyContinue:

Get-ChildItem -Path C:\ -Filter lush* -Recurse -Force `
              -ErrorAction SilentlyContinue


Directory: C:\

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-arhs        25.09.2013     12:16       1208 lush.asx
Run Code Online (Sandbox Code Playgroud)

lush.asx具有ReadOnly,HiddenSystem属性.

您可能还想通过管道来| select Name, Length, Directory摆脱那条不幸的Directory: C:\路线.DirectoryName如果你想要没有文件名的完整路径,还有一个.