I'm trying to write a loop for replacing the all the matching values.
Key Value
--- -----
client xxxx
type Test
name xxx
env ALL
and I have another app.config file, looks as follows,
<add key="ClientName" value="{{client}}" />
<add key="InstallForClients" value="{{client}}" />
I'm tring to match each and every string (which exits between two curly braces ) with each and every key in dictionary. if it is match, replace string with value.
I'm not able to replace the values. Here is the powershell script I'm working on,
if ("$string" -eq "$stringtocheck")
{
echo "Replacing $stringtocheck with $newstring in $source"
(Get-content $source) | ForEach-Object { $_ -replace '{{$stringtocheck}}', $newstring } | Set-Content $destination
}
}
Can someone please help me in updating this replacing loop.
-replace '{{$stringtocheck}}'you should change the single quotes to double quotes if you want to use the value of your $stringtocheck variable