Reading Registry Values with Powershell

by Mar 5, 2012

In a previous tip we presented the functions New-RegKey and Set-RegistryValue to you which made creating registry keys and values very easy. Here is the missing Get-RegistryValue function which again is very easy to use to check the value of any registry value:

function Get-RegistryValue {
  param(
    $key,
    $name
  )
  
  $key = $key -replace ':',''
  $regkey = "Registry::$key"
  Get-ItemProperty -Path $regkey -Name $name | 
    Select-Object -ExpandProperty $name
}

And this is how you can use it to read a single registry value:

Get-RegistryValue Key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion' Name CSDVersion

It reads the service pack version. Open regedit.exe to double-check or identify more registry values that you could read out from PowerShell.

Twitter This Tip! ReTweet this Tip!