≡ Menu

Read Remote Registry key default values using Powershell

Today I had a need to query the default value of a registry key in remote computer. There are several articles on internet which are talking about reading default value of a registry key from local machine but no one has enough information about reading default value of registry from remote computer. After some research I found the code which works for both local and remote computers.

Here you go.

$txtKey = ".txt"            
$computer = $env:computername            
$HKLM   = [microsoft.win32.registrykey]::OpenRemoteBaseKey('ClassesRoot',$computer)            
$txtref  = $HKLM.OpenSubKey($txtKey)            
$txtvalue = $txtref.GetValue($null).tostring()            
write-host $txtvalue

In this example, I am reading the default value of “HKEY_CLASSES_ROOT\.txt” registry key.  The code is self explanatory. Feel free to write in comment section if you have any questions. Happy to help.

Hope this helps..

Comments on this entry are closed.

  • Emily May 19, 2018, 1:04 am

    All it does is copy the script to the screen. Doesn’t do anything.

    • Wintel Rocks May 29, 2018, 6:08 pm

      You should get output similar to below assuming your computer has some application mapped to open .txt files.
      PS C:\> $txtKey = “.txt”
      PS C:\> $computer = $env:computername
      PS C:\> $HKLM = [microsoft.win32.registrykey]::OpenRemoteBaseKey(‘ClassesRoot’,$computer)
      PS C:\> $txtref = $HKLM.OpenSubKey($txtKey)
      PS C:\> $txtvalue = $txtref.GetValue($null).tostring()
      PS C:\> write-host $txtvalue
      txtfile
      PS C:\>