Get a Registry key value from txt files

Hi,

I am trying to get a registry value from the remote servers , i got the value but i want to know which computer has that value
and i am not able to that , Can someone help to get a output like Computername1 : regsitry value , Computername12 : regsitry value …

$servers = Get-Content “C:\Users\servers.txt”
$reg= “HKLM:\SYSTEM\CurrentControlSet\Control\Rsa”
foreach ($server in $servers)
{
(Get-ItemProperty -path $Reg -name “Packages”).“Packages”

}

From what I understand, you can’t get remote registry settings like that… This goes into detail:

https://itfordummies.net/2016/09/06/read-remote-registry-powershell/

Here’s a script I ran to get info from the SQL registry keys on remote servers:

#Specify the file path to list of servers to run this script against

$computers = gc "X:\Folder\Servers.txt"

Clear-Host

foreach ($Computer in $Computers) 
{
if ((Test-Path -Path \\$computer\C$)){
    $computerSystem = get-wmiobject Win32_ComputerSystem -Computer $Computer
#Gather SQL Edition (Express or Standard) and SQL Version Number from Registry
 
    $machinename = $computer
    $key = "Software\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL"
    $valuename = "SQLServer"

    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $machinename)
    $regkey = $reg.opensubkey($key)
    
        $p = $regkey.getvalue($valuename)
	    $KeyEd = "SOFTWARE\\Microsoft\\Microsoft SQL Server\\$p\\Setup"
	    $valueEd = "Edition"
	    $valueVer = "Version"
	    $regkeysetup = $reg.opensubkey($keyed)
	    $e = $regkeysetup.getvalue($ValueEd)
	    $v = $regkeysetup.getvalue($valueVer)

        write-host "System Information for: " $computerSystem.Name -BackgroundColor DarkCyan
        "-------------------------------------------------------"
        Write-Output 
        "SQL Version: " + $ValueVer
        "SQL Edition: " + $ValueEd
}
else
{write-host "$computer is unreachable or does not exist" -BackgroundColor DarkCyan}
}

I’m fairly new to this, so there is probably a quicker way of doing this… But this has worked great for me and I’ve done it with multiple registry keys.

Another way of doing it would be via PowerShell Remoting and to return a custom object.

$servers = Get-Content "C:\Users\servers.txt"

$result = Invoke-Command -ComputerName $servers -ScriptBlock {
  $reg= 'HKLM:\SYSTEM\CurrentControlSet\Control'
  [PSCustomObject] @{
    ComputerName = $env:COMPUTERNAME
    Value = (Get-ItemProperty -path $reg -name SystemBootDevice).SystemBootDevice
  }
}
$result

Thanks a lot …

PS remoting is not enable i had try the scrip below and i am getting the error, Can anyone help on this

$computers = gc “C:\Servers.txt”

foreach ($Computer in $Computers)
{
$computerSystem = get-wmiobject Win32_ComputerSystem -Computer $Computer

$machinename = $computer

$key = ‘HKLM:\SYSTEM\CurrentControlSet\Control\Lsa’

$valuename = (“Packages”).‘Packages’

$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(‘LocalMachine’, $machinename)

$regkey = $reg.opensubkey($key)

$regkey.getvalue($valuename)
}

$Results = $MachineName , $keyValue

Write-host $Results

You cannot call a method on a null-valued expression.
At line:8 char:14

  • $key.GetValue <<<< ($Value)
    • CategoryInfo : InvalidOperation: (GetValue:String) , RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull