Question: **values.ini** looks like

```
[default]
A=1
B=2
C=3

```

**foo.txt** looks like

```none
Now is the %A% for %a% %B% men to come to the %C% of their %c%

```

I want to use Powershell to search for all of the %x% values in **values.ini** and then replace every matching instance in **foo.txt** with the corresponding value, case insensitively; generating the following:

```none
Now is the 1 for 1 2 men to come to the 3 of their 3

```

Answer: 
Assuming PowerShell version 3.0 or newer, you can use the `ConvertFrom-StringData` cmdlet to parse the key-value pair in your ini file, but you'll need to filter out the `[default]` directive:

```
# grab relevant lines from file
$KeyValPairs = Get-Content .\values.ini | Where {$_ -like "*=*" }

# join strings together as one big string
$KeyValPairString = $KeyValPairs -join [Environment]::NewLine

# create hashtable/dictionary from string with ConvertFrom-StringData
$Dictionary = $KeyValPairString |ConvertFrom-StringData

```

You can then use the `[regex]::Replace()` method to do a lookup against the dictionary for each match you want to replace:

```
Get-Content .\foo.txt |ForEach-Object { 
    [Regex]::Replace($_, '%(\p{L}+)%', {
        param($Match)

        # look term up in dictionary
        return $Dictionary[$Match.Groups[1].Value]
    }) 
}

```
I found a simpler solution using this [INI script](http://lipkau.github.io/PsIni/) called **Get-IniContent**.

```
#read from Setup.ini
$INI = Get-IniContent .\Setup.ini
$sec="setup"

#REPLACE VARIABLES
foreach($c in Get-ChildItem -Path .\Application  -Recurse -Filter *.config)
{
  Write-Output $c.FullName
  Write-Output $c.DirectoryName

  $configFile = Get-Content $c.FullName -Raw
  foreach($v in $INI[$sec].Keys)
  {
    $k = '%'+$v+'%'
    $match = [regex]::IsMatch($configFile, $k)
    if($match)
    {
      $configFile = $configFile -ireplace [regex]::Escape($k), $INI[$sec][$v]
    }
  }
  Set-Content $c.FullName -Value $configFile 
}

```