PowerShell - 列出我系统上的所有 SQL 实例?
是否有 Powershell 命令可以列出我的系统上的所有 SQL 实例? (微软 SQL 2008)
Is there a Powershell command to list all SQL instances on my system? (MS SQL 2008)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
只是另一种方法...可以比 SQLPS 更快一点来获得快速答案。
Just another way of doing it...can be a little quicker than SQLPS to get a quick answer.
导入 powershell sql server 扩展:
然后执行以下命令
Import powershell sql server extensions:
Then do these commands
我发现(至少对我来说)以上都没有返回我的 SQL Express 实例。我有 5 个命名实例、4 个全功能 SQL Server、1 个 SQL Express。上面的答案中包含了 4 个全脂,而 SQL Express 则没有。所以,我在互联网上做了一些挖掘,发现了 这篇文章,作者:James Kehr,其中列出了有关计算机上所有 SQL Server 实例的信息。我使用这段代码作为编写下面函数的基础。
I found that (for me at least) none of the above returned my SQL Express instance. I have 5 named instances, 4 full-fat SQL Server, 1 SQL Express. The 4 full-fat are included in the answers above, the SQL Express isn't. SO, I did a little digging around the internet and came across this article by James Kehr, which lists information about all SQL Server instances on a machine. I used this code as a basis for writing the function below.
通过使用 System.Data.Sql 命名空间,您可以在 Windows Power shell 中使用以下命令获取计算机上的所有 MSSQL 实例:
[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources()
By using the
System.Data.Sql
namespace you can get all MSSQL instances on a machine using this command in windows power shell:[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources()
Aaron 方法返回更确定的响应。
请阅读此处了解 Instance.GetDataSources ()
Aaron method return a more sure response.
Read Here about Instance.GetDataSources()
此函数将返回所有已安装的实例,并在对象列表中包含版本详细信息:
This function it gonna return all the installed instances with the version details in a object list:
如果您希望列表包含实例使用的附带网络端口,您可以尝试此...
If you like the list to contain accompanying network ports used by the instances, you can try this...