【问题标题】:Get-ChildItem - SlowGet-ChildItem - 慢
【发布时间】:2017-02-15 18:17:49
【问题描述】:

运行 Powershell V4.0。下面是在给定日期范围内按文件名中的日期戳搜索 1000 个文件并查找所有匹配字符串的脚本。但是 Get-ChildItem cmdlet 非常慢。我是 Powershell 的新手。有什么办法可以提高效率吗?或许分批阅读?

######################################################
#Date ranges and filename
$startdate = [datetime]'01/26/2017'
$enddate = [datetime] '02/05/2017'
$Filename = "DACNBA0124IDT030"
######################################################
#Progress

######################################################


$array = 
do {
   $startdate.ToString('yyyy_MM_dd*')
   $startdate = $startdate.AddDays(1)
  }

until ($startdate -gt [datetime] $enddate)

$files = $array | foreach-object {"G:\Live Engineering\AsRuns\Test\$_*"}

write-host $files

$Matches = get-childitem $files -recurse -force -OutBuffer 20000 | select-  string $Filename | Where -Verbose {$_.line -notlike '*.mxf'}
$Matches.Matches.Count > "C:\Users\user\Desktop\report app\Log.txt"

【问题讨论】:

  • 指定模式直接在get-child-item中查找select-string或-exclude *.mxf文件。无论如何,最好看看您处理的文件的示例,它们的大小,是否是网络驱动器。
  • 为了合理快速地搜索网络附加存储上的数十万个文件,我不得不切换到cmd /c dir /b /s ...。它在我的网络上快了一个数量级。

标签: powershell-4.0 processing-efficiency get-childitem


【解决方案1】:

我有一个辅助函数,我每天在工作中都会用到它。我的 GitHub 存储库中有可用的。

我在其中有两个 cmdlet,它们的作用相同,甚至更多......

希望能帮到你。

https://github.com/kvprasoon/PSReadScript

随时发布问题/错误并在那里提出请求

问候,

Kvprasoon

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-17
    • 2011-02-22
    • 2016-11-29
    • 1970-01-01
    • 2017-02-21
    • 2012-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多