I'm trying to update each value in my hashtable with a string replacement. I tried solutions mentioned here, but to no avail.
My current code generates the values with the required replacement. But how do I get them to replace the values in my hashtable?
$mactable = [ordered]@{
"A" = "11:22:33:XX:YY:10"
"B" = "11:22:33:XX:YY:20"
"C" = "11:22:33:XX:YY:30"
"D" = "11:22:33:XX:YY:40"
"E" = "11:22:33:XX:YY:50"
}
$octet4hex = "10"
$octet5hex = "16"
foreach($value in $mactable.values){
$value -replace "XX:YY", ($octet4hex+":"+$octet5hex)
}
I tried this (as a mentioned solution):
foreach($value in @($mactable.values)){
$mactable[$key] = $value -replace "XX:YY", ($octet4hex+":"+$octet5hex)
}
But that gives me the following error:
Index operation failed; the array index evaluated to null.
Expected result is:
"A" = "11:22:33:10:16:10"
"B" = "11:22:33:10:16:20"
"C" = "11:22:33:10:16:30"
"D" = "11:22:33:10:16:40"
"E" = "11:22:33:10:16:50"