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?

link|flag
Not really an answer to your question, but have you considered not using .reg files, but using a powershell script to modify the registry? – Lars Truijens 2 hours ago
Hi Lars. There's a couple of reasons to use the .reg files: 1) Separation of script logic from configuration (so that a new version of the reg files can be published without needing to modify & re-sign the deployment scripts) 2) Not having to reinvent the wheel by coming up with a new way to store registry information that's not compatible with Regedit 3) Continuing to support the existing infrastructure which is based on the reg files. 4) The .reg files provide a configuration mechanism for legacy machines without PowerShell, and I don't want to maintain two sets of configuration. – Hydrargyrum 1 hour ago

1 Answer

As far as I know, basic PowerShell Cmdlets don't use .reg file at all.

So, on one hand you can modify your reg files and apply them with REG.EXE. On the other hand you can use PowerShell registry provider an 'Item' CMdlets to modify your registry.

link|flag

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.