Skip to content

Instantly share code, notes, and snippets.

@Kevin-Bronsdijk
Created July 28, 2015 16:05
Show Gist options
  • Save Kevin-Bronsdijk/ca6d4d3453bffd4bb643 to your computer and use it in GitHub Desktop.
Save Kevin-Bronsdijk/ca6d4d3453bffd4bb643 to your computer and use it in GitHub Desktop.
JiraNetworkerrorIOException
#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