Created
July 28, 2015 16:05
-
-
Save Kevin-Bronsdijk/ca6d4d3453bffd4bb643 to your computer and use it in GitHub Desktop.
JiraNetworkerrorIOException
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Gather SMO exception details | |
function SmoException | |
{ | |
$err = $_.Exception | |
while ( $err.InnerException ) | |
{ | |
$err = $err.InnerException; | |
}; | |
Write-Host $err.Message; | |
} | |
Import-Module SQLPS -DisableNameChecking | |
$SQLBrowserServiceName = "SQLBrowser" | |
Try | |
{ | |
#The sql browser service must be installed and running | |
if ((Get-Service $SQLBrowserServiceName -ErrorAction Stop | Where-Object {$_.status -eq "running"}).count -eq 0 ) | |
{ | |
Write-Host "Starting $SQLBrowserServiceName" | |
Start-Service $SQLBrowserServiceName -ErrorAction Stop | |
} | |
$ManagedComputer = New-Object 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' | |
#Gather data | |
foreach ($ServerInstanceMC in $ManagedComputer.ServerInstances) | |
{ | |
foreach ($ServerProtocol in $ServerInstanceMC.ServerProtocols | Where {$_.Displayname -eq 'TCP/IP'} ) | |
{ | |
if (!$ServerProtocol.IsEnabled) | |
{ | |
$ServerProtocol.IsEnabled = 1; | |
$ServerProtocol.Alter(); | |
Restart-Service ('MSSQL$' + $ServerInstanceMC.Name) -Force | |
} | |
} | |
} | |
} | |
Catch | |
{ | |
SmoException $_.Exception | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment