title: Import script-modified .reg files with PowerShell?
body: <p>I need to import a .reg file that contains standard configuration settings for a server product. However, it's possible that a single Windows box might contain multiple server instances. Each server instance has its own configuration keys in the Windows registry.</p>
  
  <p>The first instance will have the default registry key:</p>
  
  <pre><code>HKLM\SOFTWARE\&lt;Vendor&gt;\&lt;Product&gt;\Settings
  </code></pre>
  
  <p>Any other instances will have variant names, eg:</p>
  
  <pre><code>HKLM\SOFTWARE\&lt;Vendor&gt;\&lt;Product&gt;\Settings-foo
  HKLM\SOFTWARE\&lt;Vendor&gt;\&lt;Product&gt;\Settings-bar
  HKLM\SOFTWARE\&lt;Vendor&gt;\&lt;Product&gt;\Settings-baz
  </code></pre>
  
  <p>etc...</p>
  
  <p>The registry file contains settings that need to be applied to each of these server instances. The structure of the registry sub-keys is the same within each key. So, the manual deployment process is to take the .reg file and do a file search-and-replace for <code>"SOFTWARE\&lt;Vendor&gt;\&lt;Product&gt;\Settings\"</code> and replace it with <code>"SOFTWARE\&lt;Vendor&gt;\&lt;Product&gt;\Settings-foo\"</code>, then import the newly tweaked .reg file. Rinse &amp; repeat for bar, baz etc.</p>
  
  <p>What I want to do is write a PowerShell script that gets a list of all the "Settings-" keys and does the equivalent search-and-replace before importing the .reg file. I haven't found a cmdlet that can import .reg files, so I guess I have to call reg.exe or regedit.exe. Both of those programs allow you to import the contents of a .reg file that's on disk.</p>
  
  <p>My question is, do I actually have to create .reg files and write them to disk so that I can then call <code>reg.exe /Import &lt;filename&gt;</code> or <code>regedit.exe /S &lt;filename&gt;</code>? Or is there some way I can just load the original .reg file, modify it in memory, and get reg.exe or regedit.exe to import the modified registry keys without needing to write a whole stack of .reg files to disk?</p>