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