使用powershell 设置 sql server 协议

本文涉及的产品
云数据库 RDS SQL Server,独享型 2核4GB
简介:

Configuring SQL Protocols through Windows PowerShell

Sometimes we are asked about the possibility of configuring SQL Server protocols through PowerShell.  In SQL Server 2008, the sqlps tool incorporates WMI and SMO into this powerful Windows administrator tool, making it easy to manage SQL Server protocols through PowerShell.

                To get started, run (elevated, if on Windows Vista or Windows Server 2008) sqlps.exe, which by default is located at the %ProgramFiles%\Microsoft SQL Server\100\Tools\binn\sqlps.exe; or, if your architecture is x64, it is in the same path as above, under your Program Files (x86) directory.

                Now that you have an Admin SQL PowerShell window, here are some example scripts that you can run to configure your SQL Server instance:

Get the TCP, NP, and SM objects

This script is the starting point for manipulating the protocols properties on a local default instance.  To modify this for a named instance, replace “MSSQLSERVER” with the name of your instance.

$MachineObject = new-object ('Microsoft.SqlServer.Management.Smo.WMI.ManagedComputer') .

$ProtocolUri = "ManagedComputer[@Name='" + (get-item env:\computername).Value + "']/ServerInstance[@Name='MSSQLSERVER']/ServerProtocol"

 

$tcp = $MachineObject.getsmoobject($ProtocolUri + "[@Name='Tcp']")

$np = $MachineObject.getsmoobject($ProtocolUri + "[@Name='Np']")

$sm = $MachineObject.getsmoobject($ProtocolUri + "[@Name='Sm']")

 

Enable remote connection protocols

Once you have the base protocol objects, enabling remote connections is trivial:

$np.IsEnabled = $true

$np.alter()

$tcp.IsEnabled = $true

$tcp.alter()

Calling the .alter() method commits changes you make to the registry, and you will need to restart the SQL Server instance for it to pick up these changes.

More elaborate example: Modifying an instance’s TCP Port

Once you have the TCP object, you can view the properties of the TCP Ports on the various IP Addresses your SQL Server instance is listening on.  For instance, this command will show the properties of the “IPAll” IP Address:

$MachineObject.getsmoobject($tcp.urn.value + "/IPAddress[@Name='IPAll']")

The following commands will make your server listen on the TCP port 3344, by modifying the TcpPort property of the IPAll entry and then committing those changes:

$MachineObject.getsmoobject($tcp.urn.Value + "/IPAddress[@Name='IPAll']").IPAddressProperties[1].Value = "3344"

$tcp.alter()

You can now verify in the SQL Server Configuration Manager that your IPAll setting is now set to listen on TCP Port 3344, and restarting the SQL Server service will result in it now listening on the newly-specified port


    本文转自 Fanr_Zh 博客园博客,原文链接:http://www.cnblogs.com/Amaranthus/archive/2011/08/09/2132232.html,如需转载请自行联系原作者





相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情: https://www.aliyun.com/product/rds/sqlserver
相关文章
|
5月前
|
SQL 存储 运维
Windows server 2016——SQL server T-SQL查询语句
Windows server 2016——SQL server T-SQL查询语句
46 0
Windows server 2016——SQL server T-SQL查询语句
|
5月前
|
SQL 安全 数据库
SQL Server 2022 安装步骤——SQL Server设置身份验证教程
SQL Server 2022 安装步骤——SQL Server设置身份验证教程
217 0
|
7月前
|
SQL 网络协议 安全
SQL Server远程登录失败
SQL Server远程登录失败
406 0
SQL Server远程登录失败
|
SQL 网络协议 程序员
【Sql Server】2019设置远程访问
本地电脑安装的ssms连接到服务器的ssms
1242 0
【Sql Server】2019设置远程访问
|
SQL 存储
sql server 2005 链接服务器:未将服务器 配置为用于 RPC
原文:sql server 2005 链接服务器:未将服务器 配置为用于 RPC  RPC: 远程过程调用(Remote Procedure Calls) --LinkedServer.Rpc 属性: --获取或设置 Boolean 属性值,该值指定链接服务器是否支持远程过程调用 (RPC)。
1800 0