Skip to content

Instantly share code, notes, and snippets.

@stefanteixeira
Created August 25, 2015 19:58
Show Gist options
  • Save stefanteixeira/287d35a48216c8be8341 to your computer and use it in GitHub Desktop.
Save stefanteixeira/287d35a48216c8be8341 to your computer and use it in GitHub Desktop.
WMI script to configure IP1 properties for SQL Server TCP Configuration
set wmiComputer = GetObject( _
"winmgmts:" _
& "\\.\root\Microsoft\SqlServer\ComputerManagement12")
set tcpProperties = wmiComputer.ExecQuery( _
"select * from ServerNetworkProtocolProperty " _
& "where InstanceName='MSSQLSERVER' and " _
& "ProtocolName='Tcp' and IPAddressName='IP1'")
for each tcpProperty in tcpProperties
dim setValueResult, requestedValue
if tcpProperty.PropertyName = "Enabled" then
requestedValue = true
elseif tcpProperty.PropertyName = "TcpPort" then
requestedValue = "1433"
elseif tcpProperty.PropertyName ="TcpDynamicPorts" then
requestedValue = "0"
end if
if tcpProperty.PropertyName <> "Enabled" then
setValueResult = tcpProperty.SetStringValue(requestedValue)
if setValueResult = 0 then
Wscript.Echo "" & tcpProperty.PropertyName & " for IP1 set."
else
Wscript.Echo "" & tcpProperty.PropertyName & " for IP1 failed!"
end if
elseif tcpProperty.PropertyName = "Enabled" then
setValueResult = tcpProperty.SetFlag(requestedValue)
if setValueResult = 0 then
Wscript.Echo "" & tcpProperty.PropertyName & " for IP1 set."
else
Wscript.Echo "" & tcpProperty.PropertyName & " for IP1 failed!"
end if
end if
next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment