Creating Registered Servers via Powershell in SSMS

本秂侑毒 提交于 2019-12-25 03:14:58

问题


A cool trick that used to work for me is creating Registered Server groups and registrations in SQL Server Management Studio via PowerShell. However, now that I am running the current version (SSMS 17.9.1) I find the functionality has been lost. I'm not sure when it broke.

After installing the SQLServer module:

Install-Module -Name SqlServer

you can open a PowerShell prompt by right-clicking on server group in the Registered Servers window, and clicking Start Powershell. Here, in the past, I've been able to create new groups and registrations with commands like:

Set-Location "sqlserver:\SQLRegistration\Database Engine Server Group"
# group
New-Item -Path "sqlserver:\SQLRegistration\Database Engine Server Group\AllServers"
# registration
New-Item -Name $(encode-sqlname 'sqlsrv') -path "sqlserver:\SQLRegistration\Database Engine Server Group\AllServers" -ItemType Registration -Value ("Server=sqlsrv ; integrated security=true");

These commands still run without error. But the new server registrations are not shown in the Registered Servers window afterwards after a refresh (or even a reboot).

And, server groups and registrations that are setup in the Registered Servers window are not shown with Get-Item/Get-ChildItem at the PowerShell prompt.

Is this functionality still working for anyone else in the current version?

I'm guessing something changed when the SQLPS powershell module were supplanted with the SQLServer module, but that's just a guess. If so I'm hoping there is just a tweak I need to use these commands under the new toolset.


回答1:


This is an apparent bug in version 21.1.18068 of the SQLServer PowerShell module. Uninstalling that version and installing 21.0.17279 resolves the issue.

uninstall-module SQLServer
install-module -RequiredVersion 21.0.17224 -Name SQLServer


来源:https://stackoverflow.com/questions/53602992/creating-registered-servers-via-powershell-in-ssms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!