Skip to content

Commit cd66271

Browse files
authored
Install SqlServer module via Save-Module to pwsh-only modules path (#608)
Install the `SqlServer` module via `Save-Module` into `C:\Program Files\PowerShell\Modules` (pwsh-only path) instead of `pwsh -Command 'Install-Module …'`. Why: - Avoids the pwsh 7.6 PowerShellGet AV crash on Server 2022 by running the install under Windows PowerShell 5.1. - Targets the pwsh-only modules path, so PS 5.1 keeps resolving `Invoke-Sqlcmd` to the existing SQLPS 16 — preserves the historical "two worlds" split and avoids SqlServer 22's strict-SSL defaults breaking in-container localhost SQL connections. - pwsh 7 still gets `SqlServer 22.2.0` (verified via `Import-Module` post-install). Verified locally with `New-BcContainer` against freshly built ltsc2019, ltsc2022, and ltsc2025 generic images — all reach "Ready for connections!" and pass `Set SQL Server memory limit`. --------- Co-authored-by: aholstrup1 <aholstrup1@users.noreply.github.com>
1 parent 7e05ee3 commit cd66271

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

generic/Run/SetupGeneric2.ps1

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,24 @@ Write-Host "only24=$env:only24"
33
$filesonly = $env:filesonly -eq 'true'
44
$only24 = $env:only24 -eq 'true'
55
if (-not $filesonly) {
6-
Write-Host 'Installing SqlServer Module in PowerShell 7'
7-
pwsh -Command 'Install-Module -Name SqlServer -RequiredVersion 22.2.0 -Scope AllUsers -Force'
6+
Write-Host 'Installing SqlServer Module to PowerShell 7 modules path'
7+
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
8+
9+
Install-PackageProvider -Name NuGet -Force -Scope AllUsers | Out-Null
10+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
11+
12+
# Save to the pwsh-only modules path so PS 5.1 keeps resolving Invoke-Sqlcmd to SQLPS
13+
$pwshModulesPath = 'C:\Program Files\PowerShell\Modules'
14+
if (-not (Test-Path $pwshModulesPath)) {
15+
New-Item -ItemType Directory -Path $pwshModulesPath -Force | Out-Null
16+
}
17+
Save-Module -Name SqlServer -RequiredVersion 22.2.0 -Path $pwshModulesPath -Force
18+
19+
Write-Host 'Verifying SqlServer module loads in PowerShell 7'
20+
pwsh -NoProfile -Command 'Import-Module -Name SqlServer -RequiredVersion 22.2.0 -ErrorAction Stop'
21+
if ($LASTEXITCODE -ne 0) {
22+
throw "SqlServer module 22.2.0 failed to import in PowerShell 7 (pwsh exit $LASTEXITCODE)"
23+
}
24+
825
Write-Host 'Done'
926
}

0 commit comments

Comments
 (0)