小编dcr*_*ven的帖子

提高PowerShell脚本的效率

下面的代码从list.txt文件中搜索400多个数字,以查看它是否存在于指定的文件夹路径中的任何文件中.

该脚本非常慢并且尚未完成,因为它在运行25分钟后没有完成.我们正在搜索的文件夹是507 MB(532,369,408字节),它包含1,119个文件480个文件夹.任何有助于提高搜索速度和效率的帮助都非常感谢.

$searchWords = (gc 'C:\temp\list.txt') -split ','
$results = @()
Foreach ($sw in $searchWords)
{
    $files = gci -path 'C:\Users\david.craven\Dropbox\Asset Tagging\_SJC Warehouse_\_Project Completed_\2018\A*' -filter "*$sw*" -recurse

    foreach ($file in $files)
    {
        $object = New-Object System.Object
        $object | Add-Member -Type NoteProperty –Name SearchWord –Value $sw
        $object | Add-Member -Type NoteProperty –Name FoundFile –Value $file.FullName
        $results += $object
    }

}

$results | Export-Csv C:\temp\output.csv -NoTypeInformation
Run Code Online (Sandbox Code Playgroud)

powershell performance coding-efficiency

3
推荐指数
1
解决办法
236
查看次数