-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprovision-sql-server-common.ps1
More file actions
67 lines (63 loc) · 2.69 KB
/
Copy pathprovision-sql-server-common.ps1
File metadata and controls
67 lines (63 loc) · 2.69 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
$env:SQL_SERVER_INSTANCE_NAME = "SQLSERVER"
$env:SQL_SERVER_INSTANCE = "SQL\$env:SQL_SERVER_INSTANCE_NAME"
$env:SQL_SERVER_PRIMARY_INSTANCE = "SQL1\$env:SQL_SERVER_INSTANCE_NAME"
$env:SQL_SERVER_SERVICE_NAME = "MSSQL`$$env:SQL_SERVER_INSTANCE_NAME"
$env:SQL_SERVER_FQDN = "sql.example.test"
function Get-StringSha256Hash {
param (
[string]$InputString
)
$stringBytes = [System.Text.Encoding]::UTF8.GetBytes($InputString)
$sha256 = [System.Security.Cryptography.SHA256]::Create()
$hashBytes = $sha256.ComputeHash($stringBytes)
$hashString = [System.BitConverter]::ToString($hashBytes) -replace '-', ''
return $hashString.ToLower()
}
function Get-SqlServerSetup {
# see https://www.microsoft.com/en-us/sql-server/sql-server-downloads
# see https://learn.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-from-the-command-prompt?view=sql-server-ver17
# see https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Microsoft/SQLServer/2022/Developer/
$archiveUrl = 'https://download.microsoft.com/download/4ba126fc-a6a0-4810-80e9-c0182d3e1f62/SQL2025-SSEI-EntDev.exe'
$mediaPath = "C:\vagrant\tmp\SQLSERVER-$(Get-StringSha256Hash $archiveUrl)"
$setupPath = "c:\tmp\SQLSERVER-$(Get-StringSha256Hash $archiveUrl)\setup.exe"
# download setup.
if (!(Test-Path $setupPath)) {
if (!(Test-Path $mediaPath)) {
mkdir $mediaPath | Out-Null
}
$archiveName = Split-Path -Leaf $archiveUrl
$archivePath = "$mediaPath\$archiveName"
if (!(Test-Path $archivePath)) {
Write-Host "Downloading $archiveName SQL Server Bootstrap Installer..."
(New-Object Net.WebClient).DownloadFile($archiveUrl, $archivePath)
}
$sfxPath = "$mediaPath\SQL*ENU.exe"
if (!(Test-Path $sfxPath)) {
Write-Host "Downloading SQL Server Setup..."
&$archivePath `
/ENU `
/LANGUAGE=en-US `
/ACTION=Download `
/MEDIAPATH="$mediaPath" `
/MEDIATYPE=CAB `
/QUIET `
/VERBOSE `
| Out-String -Stream `
| Out-Host
if ($LASTEXITCODE) {
throw "failed with exit code $LASTEXITCODE"
}
}
Write-Host "Extracting SQL Server Setup..."
&$sfxPath `
/Q `
/X:"$(Split-Path -Parent $setupPath)" `
/VERBOSE `
| Out-String -Stream `
| Out-Host
if ($LASTEXITCODE) {
throw "failed with exit code $LASTEXITCODE"
}
}
return $setupPath
}