Reading Registry Values with Type

by Oct 10, 2014

All PowerShell Versions

Reading all registry values is simple when you do not need the data type: simply use Get-ItemProperty:

Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

If you do need the data type, a little more effort is needed:

$key = Get-Item -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

$key.GetValueNames() |
  ForEach-Object {
    $ValueName = $_

    $rv = 1 | Select-Object -Property Name, Type, Value
    $rv.Name = $ValueName
    $rv.Type = $key.GetValueKind($ValueName)
    $rv.Value = $key.GetValue($ValueName)

Twitter This Tip! ReTweet this Tip!