【发布时间】:2019-11-25 05:27:54
【问题描述】:
如何在 PowerShell 中使用单个 Get-ChildItem 命令显示和计算匹配文件?目前我正在使用两个 Get-ChildItem 命令,第一个用于计数,第二个用于显示文件 - 工作正常,但在扫描整个磁盘时不是很有效......
计算匹配的命令:
$count = Get-ChildItem -Path $searchLocation -Filter $filename -Recurse -ErrorAction SilentlyContinue | Measure-Object | %{$_.Count}
显示文件的命令:
Get-ChildItem -Path $searchLocation -Filter $filename -Recurse -ErrorAction SilentlyContinue | %{$_.FullName}
【问题讨论】:
-
简单地将所有匹配项存储在一个变量
$t = Get-ChildItem -Path $searchLocation -Filter $filename -Recurse -ErrorAction SilentlyContinue; $t.Count; $t.FullName