关闭

Managing Client Network Protocols with WMI Provider

854人阅读 评论(0) 收藏 举报

The ClientNetworkProtocol class represents the objects for client network protocols. To see the list of protocols of ClientNetworkProtocol class:

Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class ClientNetworkProtocol | Select-Object ProtocolName, ProtocolDisplayName,ProtocolOrder

 

To see all the methods you can apply to the client network protocol instances:

Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class ClientNetworkProtocol | Get-Member -memberType Method | Select-Object Name

 

To disable the Named Pipes protocol:

$clientprotocol=Get-WmiObject –namespace root\Microsoft\SqlServer\ComputerManagement10 -class ClientNetworkProtocol -filter "ProtocolName='np'"
$clientprotocol.SetDisable()

To verify the result:

Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class ClientNetworkProtocol | Select-Object ProtocolName, ProtocolDisplayName,ProtocolOrder

 

If you’d like to re-enable the Named Pipes protocol and place it above the TCP/IP protocol, which has an order of 2 in the list, you can simply use the SetOrderValue method toset the order of the Named Pipes protocol to 2, to take the place of the TCP/IP protocol:

$clientprotocol=Get-WmiObject –namespace root\Microsoft\SqlServer\ComputerManagement10 -class ClientNetworkProtocol -filter "ProtocolName=’np’"
$clientprotocol.SetOrderValue(2)

To verify the result, sort all the client network protocols by their order:
Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class ClientNetworkProtocol | Select-Object ProtocolName, ProtocolDisplayName,ProtocolOrder | Sort-Object ProtocolOrder

 

To get the property names and their associated protocol names of ClientNetworkProtocolProperty:

Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class ClientNetworkProtocolProperty | Select-Object PropertyName, ProtocolName

 

To change the default port of the TCP/IP protocol from 1433 to 7001:

$strComputer = "."
$protocolproperty=Get-WmiObject –computerName $strComputer –namespace root\Microsoft\SqlServer\ComputerManagement10 –class ClientNetworkProtocolProperty -filter "PropertyName=’Default Port’"
$protocolproperty.SetNumericalValue(7001)

To verify the result:

Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class ClientNetworkProtocolProperty -filter "PropertyName=’Default Port’"

 

 The complete script(ChangeTCPIPDefaultPort.ps1):

$wmi=Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class ServerNetworkProtocolProperty `
-filter "PropertyName='TcpPort' and IPAddressName='IPAll' and InstanceName='MSSQLSERVER'?

$wmi.SetStringValue(7001) | Out-Null

$sqlservice = Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class SqlService `
-filter "ServiceName='MSSQLSERVER'"

$sqlservice.StopService() | Out-Null

$sqlservice.StartService() | Out-Null

# Confirm the default port number has been changed
Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class ServerNetworkProtocolProperty `
-filter "PropertyName='TcpPort' and IPAddressName='IPAll' and InstanceName='MSSQLSERVER'" | Select-Object PropertyStrVal

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:658186次
    • 积分:8533
    • 等级:
    • 排名:第2358名
    • 原创:176篇
    • 转载:23篇
    • 译文:49篇
    • 评论:80条
    最新评论