Converting the Windows Script Host RegWrite Method
Definition: Creates a new key, adds another value-name to an existing key (and assigns it a value), or changes the value of an existing value-name.
Creating a new registry key just might be the easiest thing you’ll ever do in Windows PowerShell; that’s because all you have to do is call the New-Item cmdlet followed by the path to the new key. For example, this command creates a new registry key named Test, a key to be created in the HKEY_CURRENT_USER (HKCU) registry hive and as a subkey of the Software key:
Told you that would be easy, didn’t we?
Creating a new registry value is a tiny bit more complicated, but not by much. To create a new registry value you use the New-ItemProperty cmdlet; in Windows PowerShell registry values are treated as if they were properties of the registry key where they reside. When you call New-ItemProperty you need to include three parameters:
The path to the registry key where the value is to be created.
The –name parameter, followed by the name to be given the new value.
The –type parameter, followed by the type of value to be created (i.e. String; ExpandString; DWORD; Binary; MultiString; Qword).
Note. Alternatively you can also include the –value parameter, followed by an initial value for the registry value. (Hey, if we could have included the word value more times in that one sentence we would have.)
Here’s an example of a command that creates a new DWORD registry value named NewValue:
New-ItemProperty HKCU:\Software\Test -name NewValue -type DWORD
If you want to modify the value of a registry value then use the Set-ItemProperty cmdlet, followed by the registry key where the value resides; the name of the registry value (the –name parameter); and the new value to be assign (the –value parameter). The whole thing should look a little something like this:
Set-ItemProperty HKCU:\Software\Test -name NewValue -value 44