Read Registry Value by Powershell Script

Description

In this article, I am going to write Powershell Script examples to read registry value using Powershell Script’s Get-ItemProperty Cmdlet, read registry value by WMI Class StdRegProv in Powershell and read remote registry value by OpenRemoteBaseKey and WMI.

Summary

Read Registry Value using Get-ItemProperty Cmdlet in Powershell

You can read registry values from specific registry key by using following Powershell command:

Get-ItemProperty "HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstallVLC media player"
Powershell Script to Read Registry Value

Powershell Script to Read Registry Value using WMI Class StdRegProv

You can read registry value using WMI Class StdRegProv in Powershell by following script:

$HKLM = [UInt32] "0x80000002"
$registry = [WMIClass] ".rootdefault:StdRegProv"
$valueName = "DisplayVersion"
$registry.GetStringValue($HKLM, 
   "SOFTWAREMicrosoftWindowsCurrentVersionUninstallVLC media player", $valueName)

Read Remote Registry Value in Powershell by OpenRemoteBaseKey

Use the below script to read registry value from remote machine by using Powershell‘s OpenRemoteBaseKey. Replace the value for variable $computer with your own remote computer name.

$computer = "hp-pc"
$w32reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$computer )
$keypath = 'SOFTWAREMicrosoftWindowsCurrentVersionUninstallVLC media player'
$productKey = $w32reg.OpenSubKey($keypath)
$productVersion = $productKey.GetValue('DisplayVersion')
write-output $productVersion
Powershell script to Read Remote Registry Value from Remote Machine

Read Remote Registry Value in Powershell by WMI Class StdRegProv

Use the below script to read registry value from remote computer by using WMI Class StdRegProv in Powershell. Replace the value for variable $computer with your own remote computer name.

$HKLM = [UInt32] "0x80000002"
$computer = "hp-pc"
$registry = [WMIClass] "$computerrootdefault:StdRegProv"
$valueName = "DisplayVersion"
$registry.GetStringValue($HKLM, 
   "SOFTWAREMicrosoftWindowsCurrentVersionUninstallVLC media player", $valueName)

Thanks,
Morgan
Software Developer


Advertisement

4 thoughts on “Read Registry Value by Powershell Script”

Leave a Comment