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..