Get-ChildItem - 慢

时间:2017-02-15 18:17:49

标签: powershell-v4.0 processing-efficiency get-childitem

运行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"

1 个答案:

答案 0 :(得分:0)

我有一个辅助功能,我每天都在工作中使用它。我有我的GitHub回购。

我有两个cmdlet,它们做同样的事情......

希望能帮助你。

https://github.com/kvprasoon/PSReadScript

随意发布问题/错误并请求

的问候,

Kvprasoon

相关问题