Get-ChildItem -Recurse -Filter filename 未按预期工作;发生了什么?

Get-ChildItem -Recurse -Filter filename 未按预期工作;发生了什么?

如果我Get-ChildItem搜索整个 C:\,则找不到任何文件,但如果我将其限制在 C:\ProgramData\,则会找到一个文件。为什么?

简洁版本

Get-ChildItem C:\ -Recurse -Filter curl-ca-bundle.crt

(什么都没找到)

Get-ChildItem C:\ProgramData\ -Recurse -Filter curl-ca-bundle.crt

(发现C:\ProgramData\chocolatey\lib\curl\tools\curl-7.63.0-win64-mingw\bin\curl-ca-bundle.crt

完整版

**********************
Windows PowerShell transcript start
Start time: 20181213133922
Username: ████████████████████████
RunAs User: ████████████████████████
Configuration Name: 
Machine: ████████████████████████ (Microsoft Windows NT 10.0.17134.0)
Host Application: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -nopro
Process ID: 16060
PSVersion: 5.1.17134.407
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17134.407
BuildVersion: 10.0.17134.407
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is find-curl-certs.log
PS C:\Users\brianl> Get-ChildItem -Path C:\ -Filter curl-ca-bundle.crt -Recurse
Get-ChildItem : Access to the path 'C:\Windows\CCM\ScriptStore' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ -Filter curl-ca-bundle.crt -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Windows\CCM\ScriptStore:String) [Get-ChildItem], 
UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Access to the path 'C:\Windows\CCM\ScriptStore' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ -Filter curl-ca-bundle.crt -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Windows\CCM\ScriptStore:String) [Get-ChildItem], Una
uthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemComma
nd

Get-ChildItem : Access to the path 'C:\Windows\CSC' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ -Filter curl-ca-bundle.crt -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Windows\CSC:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Access to the path 'C:\Windows\CSC' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ -Filter curl-ca-bundle.crt -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Windows\CSC:String) [Get-ChildItem], UnauthorizedAcc
essException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemComma
nd

Get-ChildItem : Access to the path 'C:\Windows\System32\LogFiles\WMI\RtBackup' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ -Filter curl-ca-bundle.crt -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Windows\Syst...es\WMI\RtBackup:String) [Get-ChildItem], 
UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Access to the path 'C:\Windows\System32\LogFiles\WMI\RtBackup' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ -Filter curl-ca-bundle.crt -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Windows\Syst...es\WMI\RtBackup:String) [Get-ChildIte
m], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemComma
nd

PS C:\Users\brianl> Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recurse


    Directory: C:\ProgramData\chocolatey\lib\curl\tools\curl-7.63.0-win64-mingw\bin


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       12/13/2018     12:07         207949 curl-ca-bundle.crt
Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Diagnosis\FeedbackHub' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...sis\FeedbackHub:String) [Get-ChildItem], 
UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Diagnosis\FeedbackHub' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...sis\FeedbackHub:String) [Get-ChildIte
m], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemComma
nd

Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Diagnosis\TenantStorage\P-ARIA' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...tStorage\P-ARIA:String) [Get-ChildItem], 
UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Diagnosis\TenantStorage\P-ARIA' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...tStorage\P-ARIA:String) [Get-ChildIte
m], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemComma
nd

Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Windows\SystemData' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...dows\SystemData:String) [Get-ChildItem], 
UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Windows\SystemData' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...dows\SystemData:String) [Get-ChildIte
m], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemComma
nd

Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection\Cache' is 
denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...rotection\Cache:String) [Get-ChildItem], 
UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Windows Defender Advanced Threat
Protection\Cache' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...rotection\Cache:String) [Get-ChildIte
m], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemComma
nd

Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection\Cyber' is 
denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...rotection\Cyber:String) [Get-ChildItem], 
UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Windows Defender Advanced Threat
Protection\Cyber' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...rotection\Cyber:String) [Get-ChildIte
m], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemComma
nd

Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Windows Defender Advanced Threat Protection\Trace' is 
denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...rotection\Trace:String) [Get-ChildItem], 
UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Access to the path 'C:\ProgramData\Microsoft\Windows Defender Advanced Threat
Protection\Trace' is denied.
At line:1 char:1
+ Get-ChildItem -Path C:\ProgramData\ -Filter curl-ca-bundle.crt -Recur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\ProgramData\...rotection\Trace:String) [Get-ChildIte
m], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemComma
nd



PS C:\Users\brianl> $PSDefaultParameterValues
PS C:\Users\brianl> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17134.407
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.407
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\Users\brianl> (Get-Command Get-ChildItem).Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Compu...


PS C:\Users\brianl> (Get-PSProvider FileSystem).ImplementingType.Assembly.FullName
System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
PS C:\Users\brianl> Stop-Transcript
**********************
Windows PowerShell transcript end
End time: 20181213135005
**********************

答案1

  • 要强制进入所有子目录,请附加参数-Force
  • 为了抑制错误/避免破坏附加-ErrorAction SilentlyContinue或短路-EA 0

Get-ChildItem C:\ -Filter curl-ca-bundle.crt -Recurse -Force -EA 0

相关内容