Monday, 7 April 2014

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:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\VLC 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] "\\.\root\default:StdRegProv"
$valueName = "DisplayVersion"
$registry.GetStringValue($HKLM, 
   "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\VLC 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 = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\VLC 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] "\\$computer\root\default:StdRegProv"
$valueName = "DisplayVersion"
$registry.GetStringValue($HKLM, 
   "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\VLC media player", $valueName)


Thanks,
Morgan
Software Developer

Advertisements
Advertisements

2 comments:

  1. Wasted hours on other posts. This was clear, concise and just works. Thank you!

    ReplyDelete