Skip to content

Instantly share code, notes, and snippets.

@stefanteixeira
Created August 25, 2015 19:59
Show Gist options
  • Save stefanteixeira/12602d32416808ab538b to your computer and use it in GitHub Desktop.
Save stefanteixeira/12602d32416808ab538b to your computer and use it in GitHub Desktop.
WMI script to configure IPAll 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='IPAll'")
for each tcpProperty in tcpProperties
dim setValueResult, requestedValue
if tcpProperty.PropertyName = "TcpPort" then
requestedValue = "1433"
elseif tcpProperty.PropertyName ="TcpDynamicPorts" then
requestedValue = "0"
end if
setValueResult = tcpProperty.SetStringValue(requestedValue)
if setValueResult = 0 then
Wscript.Echo "" & tcpProperty.PropertyName & " for IPAll set."
else
Wscript.Echo "" & tcpProperty.PropertyName & " for IPAll failed!"
end if
next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment