-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-started-sql-server.ps1
33 lines (27 loc) · 1.58 KB
/
get-started-sql-server.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Run me on the server hosting your SQL Server
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install dotnet-6.0-sdk -y
choco install dotnet-6.0-runtime -y
choco install sql-server-express -y
$sql2016RegistryPath = "HKLM:\Software\Microsoft\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQLServer"
$sql2017RegistryPath = "HKLM:\Software\Microsoft\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQLServer"
$sql2019RegistryPath = "HKLM:\Software\Microsoft\Microsoft SQL Server\MSSQL15.SQLEXPRESS\MSSQLServer"
$sqlRegistryPathToUse = $null
if (Test-Path $sql2016RegistryPath)
{
$sqlRegistryPathToUse = $sql2016RegistryPath
}
elseif (Test-Path $sql2017RegistryPath)
{
$sqlRegistryPathToUse = $sql2017RegistryPath
}
elseif (Test-Path $sql2019RegistryPath)
{
$sqlRegistryPathToUse = $sql2019RegistryPath
}
New-ItemProperty -Path $sqlRegistryPathToUse -Name "LoginMode" -Value "2" -PropertyType DWORD -Force
New-ItemProperty -Path "$sqlRegistryPathToUse\SuperSocketNetLib\Tcp" -Name "Enabled" -Value "1" -PropertyType DWORD -Force
New-ItemProperty -Path "$sqlRegistryPathToUse\SuperSocketNetLib\Np" -Name "Enabled" -Value "1" -PropertyType DWORD -Force
net stop MSSQL`$SQLEXPRESS /y
net start MSSQL`$SQLEXPRESS
& "netsh" advfirewall firewall add rule "name=SQL Server" dir=in action=allow protocol=TCP localport=1433