[英]Need to make search in PowerShell script faster
誰可以幫助您更快地進行搜索? 使用此代碼搜索需要幾天的時間。 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
我自己找到了解決方案。 只是將數據(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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.