[英]Need to make search in PowerShell script faster
Who can help to make this search faster? 谁可以帮助您更快地进行搜索? With this code search takes a few days.
使用此代码搜索需要几天的时间。 Search_Names.csv (about 10k names) Need_This_Long_Strings.csv (about 180k strings and it's 50MB)
Search_Names.csv(约1万个名称)Need_This_Long_Strings.csv(约18万个字符串,共50MB)
$TimeStamp = Get-Date -Format {yyyy.MM.dd_hh.mm.ss}
$SearchNames = gc D:\Search_Names.csv
$WhereSearch = gc D:\Need_This_Long_Strings.csv
$Val = 0
foreach ($SearchName in $SearchNames)
{
$WhereSearch | Where{$_ | Select-String -Pattern "$SearchName.*"} | Out-File D:\Find_in_Search_File_$TimeStamp.log -Append
$Val = $Val + 1
}
"Count of matches - $Val" |Out-File D:\Find_in_Search_File_$TimeStamp.log -Append
I found the solution myself. 我自己找到了解决方案。 Just made the data (Need_This_Long_Strings.csv) into an array.
只是将数据(Need_This_Long_Strings.csv)放入一个数组中。 Now this code search takes a about 20 min.
现在,此代码搜索大约需要20分钟。
$TimeStamp = Get-Date -Format {yyyy.MM.dd_hh.mm.ss}
$SearchNames = Get-Content D:\Search_Names.csv
$WhereSearch = Import-Csv D:\Need_This_Long_Strings.csv -Delimiter ";"
$SearchArray = New-Object System.Collections.ArrayList($null)
$SearchArray.AddRange($WhereSearch)
$Val = 0
foreach ($_ in $SearchArray)
{
if ($SearchNames -contains $_.FullName)
{
$_ | Export-Csv D:\Find_in_Search_File_$TimeStamp.csv -Delimiter ";" -Append
$Val = $Val + 1
}
}
"Count of matches - $Val" |Out-File D:\Find_in_Search_File_$TimeStamp.log -Append
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.