Skip to content

Instantly share code, notes, and snippets.

@steviecoaster
Created September 2, 2021 03:45
Show Gist options
  • Save steviecoaster/a1fc1946c1df06a38660e983874124d8 to your computer and use it in GitHub Desktop.
Save steviecoaster/a1fc1946c1df06a38660e983874124d8 to your computer and use it in GitHub Desktop.
$ErrorActionPreference = 'Stop';
$pp = Get-PackageParameters
$packageName= 'sql-server-express'
$url = ''
$url64 = 'https://download.microsoft.com/download/8/4/c/84c6c430-e0f5-476d-bf43-eaaa222a72e0/SQLEXPR_x64_ENU.exe'
$checksum = 'a0086387cd525be62f4d64af4654b2f4778bc98d'
if($pp['InstallPath']){
$silentArgs = "/INSTALLPATH=$($pp['InstallPath']) /IACCEPTSQLSERVERLICENSETERMS /Q /ACTION=install /INSTANCEID=SQLEXPRESS /INSTANCENAME=SQLEXPRESS /UPDATEENABLED=FALSE"
}
else {
$silentArgs = "/IACCEPTSQLSERVERLICENSETERMS /Q /ACTION=install /INSTANCEID=SQLEXPRESS /INSTANCENAME=SQLEXPRESS /UPDATEENABLED=FALSE"
}
$tempDir = Join-Path (Get-Item $env:TEMP).FullName "$packageName"
if ($env:packageVersion -ne $null) {$tempDir = Join-Path $tempDir "$env:packageVersion"; }
if (![System.IO.Directory]::Exists($tempDir)) { [System.IO.Directory]::CreateDirectory($tempDir) | Out-Null }
$fileFullPath = "$tempDir\SQLEXPR.exe"
Get-ChocolateyWebFile -PackageName $packageName -FileFullPath $fileFullPath -Url $url -Url64bit $url64 -Checksum $checksum -ChecksumType 'sha1'
Write-Host "Extracting..."
$extractPath = "$tempDir\SQLEXPR"
Start-Process "$fileFullPath" "/Q /x:`"$extractPath`"" -Wait
Write-Host "Installing..."
$setupPath = "$extractPath\setup.exe"
Install-ChocolateyInstallPackage "$packageName" "EXE" "$silentArgs" "$setupPath" -validExitCodes @(0, 3010, 1116)
Write-Host "Removing extracted files..."
Remove-Item -Recurse "$extractPath"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment