There are multiple ways by which we can find a list of SQL Server instances name instances on a machine. In this blog, I would show a few ways to do it.
Command Prompt
Based on my research, registry key would have an entry whenever SQL is installed. So we can query the registry key to find details about instance name.
reg query "HKLM\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL
If we want to query services, then we can search for all services and look for display name
search query | findstr "DISPLAY_NAME"|findstr /C:"SQL Server ("
The above method of registry, can’t tell the version.
PowerShell
Whatever we did on method 1, same can be achieved using PowerShell also. Below is the method where we query the registry.
Get-ItemProperty ‘HKLM:\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL’
If we want to query services to get then another option would be to use below PowerShell
Get-Service | ?{ $_.DisplayName -like "SQL Server (*" }
Do you know any more ways? Please share with others via comment.
Here is my earlier article on the same subject:
- SQL SERVER – Find Name of The SQL Server Instance
- SQL SERVER – Introduction to SERVERPROPERTY and example
- SQL SERVER – Find Hostname and Current Logged In User Name
- SQL SERVER – Q&A: SQL Clustering Virtual Server Name and Instance Name
Reference: Pinal Dave (https://blog.sqlauthority.com)