Hi,
I have 2 Hash Tables and 99% of the time the condition is the same key will appear twice in each table. The first thing I do is remove the dup key in the 2nd table. Then, I need to find if the value associated with the key I deleted exists in the 2nd table, and if so, how many times does it occur and what keys are associated with it. In practice, these will be large Hash Tables, so I need to quickly find out how many occurences of the key exist in the 2nd table and what Keys are associated with it.
I try here to remove a key while the value still exists in the 2nd table, but this isnt working. Also, Im not correctly displaying the data from the 2nd table as well when I find it. I'd appreciate some help.
$EmpNames = $null
$EmpNames = @{}
$EmpNumbers = $null
$EmpNumbers = @{}
$EmpNames = @{John = "John"; Dave = 223344; Justine = "Justine"; Rose = 223344; "Jim" = 223344}
$EmpNumbers = @{John Doe = 112233; Dave Davis = 223344; Justine Smith = 334455; Rose Jones = 223344;"Jim Bob" = 223344;"Jim" = 223344; Dave Davis1 = 223344}
Foreach ($item in $EmpNames.GetEnumerator()) {
If ($EmpNumbers.ContainsKey($item.Name) -eq $True) {
$EmpNumbers.Remove($item.Name)
Do
{
$EmpNumbers.Remove($item.Name)
Write-Host "$EmpNumbers.($Item.Name) $EmpNumbers.$Item.Value Found"
} while ($EmpNumbers.ContainsValue($item.Value) -eq $True)
}
Else
{
Write-Host "Dup $($item.Value) Not Found"
}
} &