运行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"发布于 2017-02-17 00:57:29
我有一个助手功能,我每天都会在工作中使用它。我的GitHub存储库中有可用的。
我有两个cmdlet在它里面做相同的和更多的…
希望能帮到你。
https://github.com/kvprasoon/PSReadScript
请随时在那里发布问题/错误和请求
致以敬意,
Kvprasoon
https://stackoverflow.com/questions/42257154
复制相似问题