Managing Server Network Protocols with WMI Provider
2012-03-22 10:56
417 查看
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
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 Client Network Protocols with WMI Provider
- Managing SQL Server Services with WMI Provider
- Managing SQL Server Client Aliases with WMI Provider
- Cannot connect to WMI provider.You do not have permission or the server is unreachable.Note that you can only manager SQL Server 2005 and later version with SQL Server Configuration Manager.Invalid namespace [0x8004100e]
- Changing SQL Server Advanced Properties with WMI Provider
- Managing Windows with WMI
- 运行SQL server2005 配置管理工具出现“Cannot connect to WMI provider. You do not have permmission or the server”
- provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified
- How to Sync Your Linux Server Time with Network Time Servers (NTP)
- 关于 WMI Provider 不能连接的错误 - Cannot connect to WMI provider. You do not have permission or the server is unreachable.
- SQL Server Configuration Manager – Cannot connect to WMI provider – Invalid class [0x80041010]
- WMI Provider for Server Events
- Building a VoIP Network with Nortel's Multimedia Communication Server 5100 [ILLUSTRATED]
- Scaling Web applications with Windows 2000 Advanced Server's Network Load Balancing
- Why BCP connects to SQL Server instance which start with account of Network Service fail?
- provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified
- SQL Server Database在C#编程下遇到的问题:“provider:SQL Network Interfaces,error:26-定位指定的服务器/实例时出错”的解决办法
- provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified解决办法
- Monitor network health with ServersCheck 7.0