I\'m attempting to read a value from a registry entry with Powershell. This is fairly simple, however, one particular registry key is giving me trouble.
If I run th
Another version:
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping\Autorun.inf').'(default)'
Use Get-Item
to get an object representing the registry key:
PS > $regKey = Get-Item HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping\Autorun.inf
This gives you an instance of RegistryKey. RegistryKey
has a method named GetValue
; if the argument to GetValue
is the empty string (''
), then it will return the (default)
value:
PS > $regKey.GetValue('')
Why is this better than Get-ItemProperty
? It extends more naturally to Get-ChildItem
. Get-ChildItem
will give you a list of RegistryKey
objects. In my particular case, I wanted to list the install paths of the versions of Python installed on my machine:
PS C:\> get-childitem HKLM:\SOFTWARE\Wow6432Node\Python\PythonCore\*\InstallPath `
>> | foreach-object { $_.GetValue('') }
C:\Python26\ArcGIS10.0\
C:\Python\27\
EDIT Had to look through and old script to figure this out.
The trick is that you need to look inside the underlying PSObject to get the values. In particular look at the properties bag
$a = get-itemproperty -path "HKLM:\Some\Path"
$default = $a.psobject.Properties | ?{ $_.Name -eq "(default)" }
You can also just use an indexer instead of doing the filter trick
$default = $a.psobject.Properties["(default)"].Value;