Recommended method of handling conversion from Registry to Powershell.

tired-it

Member
Messages
241
Reaction score
23
I am not sure if this is the correct place to ask, but it may be useful for users who run post-setup tasks.

I have a running set of .REG files that I use in place of NTLite settings. Those files are separated by theme and Local v. User hive. When added to the registry section of NTLite, they merge fine into the installed image. Sometimes, I find some new changes that I want to push out to already installed systems.

I want to convert some of the registry keys from the .REG files into commands for importing through Powershell. What is an efficient method of doing so? I have read about many methods to do so, but none of them are clicking with me in the sense that they all approach the solution from a different angle.

What if the registry folder isn't there? What if there is already a key where I want to make a change? Can I force the change? What if there is an error, can I tell Powershell to ignore and continue?

When dealing with .REG files, it was as straightforward as adding a "-" to delete keys and folders. Powershell is a different beast for me.

This website seems to do the conversion for me, but I would like some help understanding the different parts of the command. I have nearly a hundred plus User hive registry keys that I want to convert into Powershell (and eventually place into a script for cycling through all users on the machine), but I know very little about Powershell (trying to learn as I go at least).
 
I'm also not a powershell guy, but my initial reaction is that the general subject of "regex" is what you're looking for. That stuff is complicated though, so unless you have the time and patience to figure it out or already have a knack for it, then it's not a good option for most. You would basically run something like Notepad++ and use find/replace with regex modifiers to reorganize keys into the command line variant:
This first part is what a registry key looks like inside a .reg file.

; Taskbar > News and interests > Disabled
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Feeds]
"EnableFeeds"=dword:00000000

This second part is what that same key looks like when installed via command line (link).

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Feeds" /v "EnableFeeds" /t REG_DWORD /d "0" /f

The gist of how to approach this would be to break the problem into different parts. While my approach would probably change as I became more familiar and experienced in this, I would likely start by first trying to replace the left bracket symbol "[" with the text of "reg add" and the filepath, so that it transforms from step A into step B as shown below.

A) [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Feeds]
B) reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Feeds]

Now we move onto the next piece, which is to replace the right bracket "]" so that it transforms from step B into step C.

B) reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Feeds]
C) reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Feeds" /v

Continue with this process until you're done figuring out how to convert a tweak from registry format into command line format. There are better ways to do what I'm saying, because you can use wildcards and more efficient regex patterns, but they can be difficult to figure out. This is really what tools and websites are doing for us when we paste data into them and they automatically organize it--someone else just took the time to figure out what regex macro they needed to create and then hosted it for others to use.

Note: The command line variant can go into many places, such as an unattended file, Run box, Command Prompt, PowerShell, Batch file, etcetera.
 
Last edited:
I appreciate the insight. I'll look into the conversion methods. Just wanted to make sure I did not waste time learning something that was either outdated or already had a good solution available that I was somehow missing.
 
If you run a .reg file from a live Windows it installs the contents too, same as if you used "reg add" or powershell. Would that work for your scenario?
 
Last edited:
If you run a .reg file from a live Windows it installs the contents too, same as if you used "reg add" or powershell. Would that work for your scenario?
There are some processes I am attempting to automate and doing so only works using a command or powershell script. So, unfortunately, running a .reg file won't work.

I admit this is partially outside the scope of NTLite because I am attempting to run this script through remoting software for testing purposes, but I also want to confirm that it works through NTLite too via Post-Setup.

Machine hive entries work as expected, but the User hive entries need to be applied to all users (who do not have admin rights) for the purposes of my testing scenario. I am know very little about powershell, so making a script is a long way out though I am trying to browse every forum I can to gleam some insight. From what I have gathered so far, there is a way to load and loop through all ntuser.dat files and apply User hive changes, but I'm not sure how.
 
Back
Top