Я бы, вероятно, использовал Python, если бы производительность была главной проблемой.Или LogParser.
Однако, если бы мне пришлось использовать PowerShell, я, вероятно, попробовал бы что-то вроде этого:
$CultureInfo = [CultureInfo]::InvariantCulture
$DateFormat = 'M/d/yyyy' # Use whatever date format is appropriate
# We need to convert the strings that represent dates. You can skip the ParseExact() calls if the dates are already in a string sortable format (e.g., yyyy-MM-dd).
$Data = Import-Csv $InputFile | Select-Object -Property ComputerName, IPAddress, MacAddress, @{n = 'CurrentDate'; e = {[DateTime]::ParseExact($_.CurrentDate, $DateFormat, $CultureInfo)}}, @{n = 'FirstSeenDate'; e = {[DateTime]::ParseExact($_.FirstSeenDate, $DateFormat, $CultureInfo)}}
$Results = @{}
foreach ($Record in $Data) {
$Key = $Record.ComputerName + ';' + $Record.MacAddress
if (!$Results.ContainsKey($Key)) {
$Results[$Key] = $Record
}
elseif ($Record.FirstSeenDate -lt $Results[$Key].FirstSeenDate) {
$Results[$Key] = $Record
}
}
$Results.Values | Sort-Object -Property ComputerName, MacAddress | Export-Csv $OutputFile -NoTypeInformation
Это может быть гораздо быстрее, потому что Group-Object
часто является узким местом дажехотя он довольно мощный.
Если вы действительно хотите попробовать использовать потоковое считывающее устройство, попробуйте использовать класс Microsoft.VisualBasic.FileIO.TextFieldParser , который является частью .Net Framework.несмотря на это немного вводящее в заблуждение название.Вы можете получить к нему доступ, набрав Add-Type -AssemblyName Microsoft.VisualBasic
.