Today, one of my colleague at work was asked to set a registry value on many computer using a login script. First try was to export value to a reg file which seems the easiest way to do it. Problem is, that one of the key in the path was dynamic and randomly generated during the installation of the product in cause. This is when Powershell comes in play!
First of all, did you know that registry can be access like a normal drive in Powershell? In fact, each hive is a drive (it sounds like a cheap rap lyrics…).
Try this and you will list the HKEY_Local_Machine hive.
cd HKLM: dir |
You can now drill down to keys using Set-Location or cd.
Back to our initial problem: How to get to a value with an unknown part…
Path of the value was looking like this: HKLM:\Software\SoftNAME\Modules\{12345678-A1B2-12A3-A123-0000A00AAAAA}\ShowSplash=0
We were lucky that in Modules there was only one sub-key in every installation but it has a new name each time we install the product.
With a simple Get-ChildItem we can retrieve the name of that mysterious key name.
$key = Get-ChildItem HKLM:\Software\SoftNAME\Modules |
Then, we used the Set-Item cmdlet to define the value of ShowSplash to 0
Set-ItemProperty -path $key -name ShowSplash -value 0 |
Because this is always cool to get a script in a one-liner, we pushed it a little further, so the final script looks like this:
Set-ItemProperty -path (Get-ChildItem HKLM:\Software\SoftNAME\Modules) -name ShowSplash -value 0 |
With classic reg and batch files, things are pretty static or inflexible. But with Powershell, it is so easy to manipulate the data and get the real information you are looking for.