需要更快地使用PowerShell脚本进行搜索



谁可以帮助更快地进行搜索?使用此代码,搜索需要几天。

Search_Names.csv(大约10k名称)

Need_This_Long_Strings.csv(约180k字符串,是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

我自己找到了解决方案。刚将数据(need_this_long_strings.csv)放入数组中。现在,此代码搜索大约需要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

相关内容

  • 没有找到相关文章

最新更新