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