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.
The first instance will have the default registry key:
HKLM\SOFTWARE\<Vendor>\<Product>\Settings
Any other instances will have variant names, eg:
HKLM\SOFTWARE\<Vendor>\<Product>\Settings-foo
HKLM\SOFTWARE\<Vendor>\<Product>\Settings-bar
HKLM\SOFTWARE\<Vendor>\<Product>\Settings-baz
etc...
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 "SOFTWARE\<Vendor>\<Product>\Settings\"
and replace it with "SOFTWARE\<Vendor>\<Product>\Settings-foo\"
, then import the newly tweaked .reg file. Rinse & repeat for bar, baz etc.
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.
My question is, do I actually have to create .reg files and write them to disk so that I can then call reg.exe /Import <filename>
or regedit.exe /S <filename>
? 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?