You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows PowerShell 5.1中Get-ChildItem -Filter参数不符合预期问题

PowerShell 5.1与7.3中Get-ChildItem通配符过滤行为差异

在包含001.sql_bk和010.sql两个文件的文件夹中执行命令:

Get-ChildItem -Path . -Filter '*.sql'

现象差异

  • Windows PowerShell 5.1:输出包含预期外的001.sql_bk文件
  • PowerShell 7.3:仅输出符合预期的010.sql文件

Windows PowerShell 5.1版本信息

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

Windows PowerShell 5.1执行输出

...
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        2023/02/09     11:09            141 001.sql_bk
-a----        2023/02/09     11:14            187 010.sql

PowerShell 7.3执行输出

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          2023/02/09    11:14            187 010.sql

差异原因

Windows PowerShell 5.1中,Get-ChildItem的-Filter参数调用Windows原生API(FindFirstFile)处理通配符,该API的过滤逻辑会将*.sql匹配所有文件名中包含.sql片段的文件(哪怕后面还有其他后缀)。PowerShell 7.3起,-Filter改用PowerShell自身的通配符解析逻辑,严格匹配以.sql结尾的文件,因此不会包含001.sql_bk这类文件。

内容的提问来源于stack exchange,提问作者aruku7230

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 04:35:46