说[假设地],我有两个 .CSV 我正在比较尝试看看我当前的哪些成员是原始成员......我写了一个嵌套的 ForEach-Object 将每个对象中的每个 $name 和 $memberNumber 与每个其他对象进行比较. 它工作得很好,但需要很长时间,特别是因为每个 CSV 都有成千上万个对象。我还有其他方法可以解决这个问题吗?
Original_Members.csv
姓名、会员号码
爱丽丝,1234
吉姆, 4567
Current_Members.csv
爱丽丝,4599
吉姆,4567
$currentMembers = import-csv $home\Desktop\current_members.csv |
ForEach-Object {
$name = $_.Name
$memNum = $_."Member Number"
$ogMembers = import-csv $home\Desktop\original_members.csv" |
ForEach-Object {
If ($ogMembers.Name -eq $name -and $ogMembers."Member Number" -eq $memNum) {
$ogMember = "Yes"
}
Else {
$ogMember = "No"
}
}
[pscustomobject]@{
"Name"=$name
"Member Number"=$memNum
"Original Member?"=$ogMember
}
} |
select "Name","Member Number","Original Member?" |
Export-CSV "$home\Desktop\OG_Compare_$(get-date -uformat "%d%b%Y").csv" -Append -NoTypeInformation