I'm having issues trying to prevent duplicate values being added to a key in powershell.
Here is my code:
foreach($row in $callLog) {
if($agentListHashTable.$agentName -contains $row.LID) {
} else {
$listID = $row.LID
$agentName = $row.Agent_Name
if($agentListHashTable.Keys -contains $agentName) {
$agentListHashTable.$agentName += ",$listID"
} else {
if($agentListHashTable.$agentName.Contains($listID)) {
break
}
$agentListHashTable.Add($agentName, $listID)
}
}
}
This adds the required keys and their values. However, in each of these keys there are multiple values that the same. An example of what the hashtable looks like is
Key: Jim Smith
Value: 1,1,1,1,1,2,2,2,2,2,22,22,44,1,1,1,1,1
However I would just like it to be:
Key: Jim Smith
Value: 1,2,22,44
I've tried doing it in the loop with something like:
if($agentListHashTable.$agentName.ContainsValue($listID)
But it doesn't work and I've looked online for how to do it outside the loop by iterating through each key and removing the duplicate values but I can't find anything.