Reading the Windows Registry from PowerShell

Reading Time: 2 minutes
Reading the Windows Registry from PowerShell
5 (100%) 2 votes

Reading the Windows registry from PowerShell can be a bit cumbersome, when all you wanted to retrieve is the value of an item under a key, at least with PowerShell version before v5.

The Get-ItemProperty can be used to enumerate the items and their values under a registry key, but retrieving a single item (previous to PS v.5) involved accessing a custom property in the returned PSCustomObject.
Only with PS v.5 the Get-ItemPropertyValue cmdlet was introduced, which actually returns the value only.
However, on Windows 2008/R2 servers, it is not always possible to update PowerShell and the .Net framework.

A “plain” call to Get-ItemProperty with a named item will return all information about the item under the specified key.
This example returns all properties of the item, including its value:

The following PSCustomObject is returned:

To actually retrieve the item’s value only, you’d need to do something like:

Of course, it is not very nice to have to repeat the item’s name.

To get around this annoyance, I have the following simple workaround helper function, which will be defined only if the PowerShell version is less than 5:

So, now also in PowerShell v3 and 4, you can just call: