Powershell Bad Code #1: Replacing values in hashtable not working
Question: Why this code is not replacing values (9 with 90) in the hashtable ? Not working Working Answer:
1 2 3 4 5 6 |
# Answer: @($hashtable.GetEnumerator()) | Where-Object -FilterScript {$_.Value -eq 9} | ForEach-Object -Process { $hashtable[$_.Key] = 90 } # Explanation: It is not possible to modify the table while iterating over it. First we need to do the iteration and then the update. |