Managing Server Network Protocols with WMI Provider

原创 2012年03月22日 10:56:01

To view the list of properties associated with each network protocol for the default instance on the local computer:

Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class ServerNetworkProtocolProperty -filter "InstanceName = 'MSSQLSERVER'" | Select-Object ProtocolName, PropertyName, IPAddressName

 

To change the port number for IPAll from 1433 to another port — for example, 3660:

# NAME: ChangeDefaultPortNumber.ps1
# COMMENT: This script change the port number of the default instance from 1433 to 3660
$wmi=Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class ServerNetworkProtocolProperty -filter "PropertyName='TcpPort' and IPAddressName='IPAll' and InstanceName='MSSQLSERVER'"
$wmi.SetStringValue(3660) | Out-Null
$sqlservice = Get-WmiObject –namespace root\Microsoft\SqlServer\ComputerManagement10 -class SqlService –filter "ServiceName='MSSQLSERVER'"  #ServiceName='MSSQL`$INSTANCE1'
$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

To assign different port numbers to different IP addresses,the complete script,DisableListenOnAllIPs.ps1, is shown here:

# . for the local computer
# If you want to connect to a remote machine, specify the machine name here.
$strComputer = "."
# Name of the targeted SQL Server instance. Here the default instance is targeted.
# For a named instance INSTANCE1, use "INSTANCE1".
$strInstanceName = "MSSQLSERVER"
$wmi=Get-WmiObject -computerName $strComputer -namespace
root\Microsoft\SqlServer\ComputerManagement10 -class ServerNetworkProtocolProperty -filter "PropertyName=’ListenOnAllIPs’
and InstanceName=’$strInstanceName’"
$wmi.SetFlag(0) | Out-Null
$sqlservice = Get-WmiObject -computerName $strComputer –namespace
root\Microsoft\SqlServer\ComputerManagement10 `
-class SqlService –filter "ServiceName=’MSSQL`$$strInstanceName’"
$sqlservice.StopService() | Out-Null
$sqlservice.StartService() | Out-Null
$wmi=Get-WmiObject -computerName $strComputer -namespace
root\Microsoft\SqlServer\ComputerManagement10 `
-class ServerNetworkProtocolProperty -filter "PropertyName=’ListenOnAllIPs’
and InstanceName=’$strInstanceName’"
# Confirm the ListenOnAllIPs property has been disabled.
Write-Host "The value of the ListenOnAllIPs property is set to " $wmi.PropertyNumVal

相关文章推荐

Managing SQL Server Client Aliases with WMI Provider

SQL Server client aliases make user connections easier, faster, and more convenient. Each alias save...

协议的使用(Working with Protocols)

在现实世界中,在处理某些情况时,人们往往需要遵守严格的程序。例如,执法官员在进行查询或收集证据时,要求“遵守协议”。 在面向对象编程的世界中,在给定的情况下,能够定义一组对象的行为是非常重要的。例如,...

How to configure XDB for using ftp and http protocols with ASM [ID 357714.1]

Configuration of XDB(XML Database) to be able to use ftp and http protocols to browse and manage ASM...

Managing Projects with GNU make 学习笔记

1. 简介 makefile定义了一种语言来描述源代码、中间文件及可执行文件之间的关系。 如果命令行指定了目标,则更新指定的目标,如果没有,则取第一个目标,也即默认目标。 1.1 目标与依赖...
  • yarsen
  • yarsen
  • 2012年03月31日 14:31
  • 1270

Miscellanies of iOS 3) Managing Memory with ARC

pp101  Not just copy and paste anymore...              For the usage of review 1. All Objective-C ...

使用Eclipse和ADT插件管理Android项目(Managing Project from Eclipse with ADT)

简介 使用Eclipse和ADT插件可以提供可视化界面和向导来创建三种类型的项目(Android项目,库项目,以及测试项目): *一个Android项目包含了将项目打包成.apk安装文件所需要的所有...

Sencha Touch 2 官方文档翻译之 Managing Dependencies with MVC(管理MVC依赖项)

前言:   如果你第一次看SenchaTouch MVC应用程序的例子,很可能会被那一个个文件夹和一堆堆js文件搞得头昏脑胀,它们之间到底有什么关系?互相之间如何协作?这就是你在下手写代码之前必须...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Managing Server Network Protocols with WMI Provider
举报原因:
原因补充:

(最多只允许输入30个字)