You need to remove leading and (or) trailing spaces. Try this:
$ht=@{} Get-Content $filename | foreach{ $key,$value = $_.Split('=') | foreach {$_.Trim()} if($key -like "line2") { $key = "line2 has been changed" } if($value -like "value2") { $value = "value2 has been changed" } $ht.Add($key,$value) } $ht.GetEnumerator() | Sort-Object nameRead full article from powershell foreach-object with if statements - Stack Overflow
No comments:
Post a Comment