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

标签 powershell search

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

gci -Path C:\ -Filter part_of_filename* -Recurse -Force | where { $_.Attributes -match "Hidden"}

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

Get-ChildItem : Access to the path 'C:\Documents and Settings' is denied. At C:\Users\USERNAME\Documents\powershell\searchdisk.ps1:10 char:5 + gci <<<< -Path C:\ -Filter part_of_filename* -Recurse -Force | where { $_.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

最佳答案

你做得对。只需在提升的控制台中运行它并删除过滤器即可。如果你不关心权限错误,附加 -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

lush.asx 具有 ReadOnlyHiddenSystem 属性。

您可能还想通过管道传送到 |选择 Name, Length, Directory 以摆脱不幸的 Directory: C:\ 行。如果您想要没有文件名的完整路径,还有一个 DirectoryName

关于powershell - 如何使用PowerShell递归搜索目录中的所有文件,包括隐藏目录中的隐藏文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26425297/

相关文章:

windows - 如何使用 Write-EventLog 在事件日志中显示任务类别的字符串名称?

powershell - 在Powershell中执行For循环以执行x次不同的服务器重启

search - URL后自动添加#gsc.tab=0

PowerShell 2.0 以及如何处理异常?

sharepoint - 使用 PowerShell 从 SharePoint 获取用户详细信息

git - 无法在 TFS 构建管道中的 PowerShell 上运行 Git pull

java - 查找包含空(非空定义)字符串的下一个位置的索引

algorithm - k = 4时k元搜索算法的操作次数?

javascript - 同时多个CreateTextRange

python - 使用python(acora)查找包含关键字的行