title: Powershell using hashtable and foreach loop to set appsettings via appcmd
body: <p>I am trying to modify the web.config of a site by adding several appsetttings. To make this code more reusable and whatnot I would like to use a hashtable to store the key-value pairs and then loop over them. I am getting errors when trying to inject the key and value into the call to appcmd. Here is my code:</p>
  <pre><code>$env:myWebsite = &quot;myWebsite&quot;
  $appcmd = &quot;C:\windows\system32\inetsrv\appcmd.exe&quot;
  
  $settings = @{
      &quot;test1&quot;=&quot;C:\Temp\test&quot;;
      &quot;test2&quot;=&quot;true&quot;;
      &quot;test3&quot;=&quot;C:\Temp\&quot;
  }
  
  foreach($s in $settings.GetEnumerator()){
      &amp; $appcmd --% set config &quot;%myWebsite%&quot; /section:appSettings /+&quot;[key='$($s.Name)',value='$($s.Value)']&quot;
  }
  </code></pre>
  <p>When I try and execute this it is not injecting s.Name and s.Value</p>