Sign in
Sethu's blog
dev@sqlservr.microsoft
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Common Tasks
Blog Home
Email Blog Author
About
Share this
RSS for comments
RSS for posts
Atom
Search Form
Tag Cloud
Extended Events
Policy Based Management
PowerShell
Resource Governor
SMO
SQL Agent
SQL Server
SQL Server 2008
Troubleshooting
Monthly Archives
Archives
November 2012
(1)
October 2012
(1)
January 2012
(1)
December 2011
(1)
July 2011
(1)
June 2011
(1)
February 2011
(1)
December 2010
(1)
November 2010
(1)
October 2010
(2)
September 2010
(1)
June 2010
(1)
February 2010
(1)
September 2009
(1)
April 2009
(1)
October 2008
(1)
July 2008
(1)
June 2008
(5)
Enable / Disable protocols in SQL Server using PowerShell
MSDN Blogs
>
Sethu's blog
>
Enable / Disable protocols in SQL Server using PowerShell
Enable / Disable protocols in SQL Server using PowerShell
Sethu Srinivasan
1 Oct 2008 4:37 PM
Comments
0
EnableProtocols.ps1
###########################################################################################
# Scenario: Enable / Disable protocols in SQL Server
# ( Thanks Michiel http://blogs.msdn.com/mwories/ for helping me out)
#
# How to use this powershell script:
# - Launch SQL Server PowerShell ( Start -> Run -> sqlps.exe)
# - Copy the following powershell script and paste it in powershell window
###########################################################################################
# Enable Disable Server Protocol
function
EnableDisableServerProtocol
{
Param
([
string
]
$serverName
=
$
(
Read-Host
"SQL Instance(like server\instance)"
)
,
[
string
]
$protocol
=
$
(
Read-Host
"Protocol name(Np / Sm / Tcp / Via)"
)
,
[
string
]
$enable
=
$
(
Read-Host
"(Enable / Disable)"
)
)
# Spilt Machine , instance names
$array
=
$serverName
.
Split
(
"\"
)
if
([
String
]::
IsNullOrEmpty
(
$serverName
))
{
write-error
"Server instance name is not valid"
return
}
$machineName
=
$array
[
0
]
if
(
$array
.
Length
-
eq
1
)
{
$instanceName
=
"MSSQLSERVER"
}
else
{
$instanceName
=
$array
[
1
]
}
$enableProtocol
=
$false
if
(
$enable
.
ToUpper
().
Equals
(
"ENABLE"
))
{
$enableProtocol
=
$true
Write-Host
"Enabling protocol "
$protocol
" on server:"
$machineName
"Instance:"
$instanceName
}
else
{
Write-Host
"Disabling protocol "
$protocol
" on server:"
$machineName
"Instance:"
$instanceName
}
$PSPath
=
"\SQL\"
+
$machineName
$machine
=
get-item
$PSPath
$sqlserverInstance
=
$machine
.
ManagedComputer
.
ServerInstances
[
$instanceName
]
$serverProtocol
=
$sqlserverInstance
.
ServerProtocols
[
$protocol
]
$serverProtocol
.
IsEnabled
=
$enableProtocol
$serverProtocol
.
Alter
()
}
EnableDisableServerProtocol
# This posting is provided "AS IS" with no warranties, and confers no rights.
# Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm
0 Comments
Leave a Comment
Name
Comment
Please add 8 and 2 and type the answer here:
Post