我想要做的是用一组哈希表(来自数据库的用户信息)过滤一个 csv 文件(恰好是一个博客)。
#$data is from a database. (about 500 items) Type: System.Data.DataTable
$users = @()
foreach($row in $data)
{
$userItem = @{
LoginId = $row[0]
LastName = $row[3]
FirstName = $row[4]
LastAccess = $null
}
$users += $userItem
}
#Log files are about 14,000 lines long
$logfiles = Get-ChildItem $logFolder -Recurse | where {$_.Extension -eq ".log"} | Sort-Object BaseName -Descending
foreach($log in $logfiles)
{
$csvLog = Import-Csv $log.FullName -Header ("Blank","LoginId","Date")
$u = $users | Select {&_.LoginId}
$filteredcsvLog = $cvsLog | Where-Object { $u -contains $_.LoginId}
#This returns null
....
}
这似乎不起作用,我错过了什么。我的猜测是我需要将数组展平为 [string[]],但我似乎也不能这样做。