If you have other properties you can just store the original object:
Users | Select *
Username : Joe.Doe
Office : Chicago
Email :
Username : Mike.Smith
Office : New York
Email :
...
UserEmails | Select *
AccountEmail : Mike.Smith
EmailAddress : [email protected]
AccountEmail : Joe.Doe
EmailAddress : [email protected]
...
Or with loops instead of
UsersCompleteList | Select *
Username : Joe.Doe
Office : Chicago
Email : [email protected]
Username : Mike.Smith
Office : New York
Email : [email protected]
...
including:for each ($user in $users) { ($user.Email = $userEmails | ? { $_.AccountEmail -eq $user.Username}).EmailAddress
在大数据集上需要花费很长时间。
$hash = @{}
$userEmails | %{ $hash[$_.AccountEmail] = $_.EmailAddress }
$users | %{ $_.Email = $hash[$_.Username] }
$hash = @{}
$userEmails | %{ $hash[$_.AccountEmail] = $_ }
$users | %{
$item = $hash[$_.Username]
$_.Email = $item.EmailAddress
$_.Other = $item.SomethingElse
}
ForEach-Object
使用公共属性合并两个数组的最快方法是什么?用户