Managing Client Network Protocols with WMI Provider

来源:互联网 发布:mac air演讲者模式 编辑:程序博客网 时间:2024/05/21 10:31

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

 

原创粉丝点击