It’s a one line code. Make sure you run this code on a SQL server. OR on your computer where SQL Admin Console is installed.
Note: Make sure SQL Browser service is started on the computer you are running this code.
Open PoweShell, copy/paste this line:
[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources()
That is it. Here is the sample Output:
