我试图使用Power Shell从多个文件中提取记录,我编写的脚本正在遍历每个文件并将匹配模式的记录写入输出文件。但由于文件数量庞大,这需要很长时间使用PowerShell优化脚本以从多个文件中提取记录
我想知道这是否可以优化。
$files = Get-ChildItem $sourcedirectory\*
for ($i=0; $i -lt $files.Count; $i++) {
$outfile = $files[$i].FullName + "_out"
Get-Content $files[$i].FullName| Select-String -Pattern "OB_[0-9]F_AHU*" | Set-Content $outfile
}
if (!(Test-Path -path $targetdirectory)) {New-Item $targetdirectory -Type Directory}
Move-Item -Path $sourcedirectory\*_out -Destination $targetdirectory
您可能会想要查看PowerShell作业或多线程方法的运行空间。模块PoshRSJobs很有用;它提供了一种“类似工作”的方式来处理运行空间。 – Robin
谢谢@Robin。让我看看 –
你使用的是什么版本的PowerShell('$ PSVersionTable.PSVersion.Major')? –