More succinct way of getting a registry value as a string than (Get-ItemProperty $key $valueName)._VALUENAME_? More succinct way of getting a registry value as a string than (Get-ItemProperty $key $valueName)._VALUENAME_? powershell powershell

More succinct way of getting a registry value as a string than (Get-ItemProperty $key $valueName)._VALUENAME_?


I'm new to PowerShell, but it seems to work in PowerShell 2 and 3 if you leave out the registry value name in Get-ItemProperty, using the value name only as a property:

(Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion).CommonFilesDir

or even shorter with the alias:

(gp HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion).CommonFilesDir

No repetition of the value name, clean, and it can't get much more succinct.


This is no less clunky, but there's no repetition if that's an itch you need to scratch:

(gi HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion).GetValue("CommonFilesDir")

(personally I'd use $env:commonprogramfiles but that's besides the point.)


What about:

Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion | `    Select CommonFilesDir