diff --git a/PreBuild.ps1 b/PreBuild.ps1 new file mode 100644 index 0000000..9cdc774 --- /dev/null +++ b/PreBuild.ps1 @@ -0,0 +1,25 @@ + +[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null +[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | Out-Null + +$serverName = $env:COMPUTERNAME +$instanceName = 'SQL2019' + +$smo = 'Microsoft.SqlServer.Management.Smo.' +$wmi = new-object ($smo + 'Wmi.ManagedComputer') + +# Enable TCP/IP +$uri = "ManagedComputer[@Name='$serverName']/ServerInstance[@Name='$instanceName']/ServerProtocol[@Name='Tcp']" +$Tcp = $wmi.GetSmoObject($uri) +$Tcp.IsEnabled = $true +$TCP.alter() + +# Enable named pipes +$uri = "ManagedComputer[@Name='$serverName']/ ServerInstance[@Name='$instanceName']/ServerProtocol[@Name='Np']" +$Np = $wmi.GetSmoObject($uri) +$Np.IsEnabled = $true +$Np.Alter() + +Set-Service SQLBrowser -StartupType Manual +Start-Service SQLBrowser +Start-Service "MSSQL`$$instanceName"