@@ -14,16 +14,13 @@ param(
1414
1515Write-Host " Downloading and installing tSQLt..." - ForegroundColor $Color
1616
17- # BaseUrl gets the latest version by default - blocked by https://github.com/LowlyDBA/dba-multitool/issues/165
18- $Version = " 1-0-5873-27393"
19- $DownloadUrl = " http://tsqlt.org/download/tsqlt/?version=" + $Version
17+ $DownloadUrl = " http://tsqlt.org/download/tsqlt/?version="
2018$TempPath = [System.IO.Path ]::GetTempPath()
2119$ZipFile = Join-Path $TempPath " tSQLt.zip"
2220$ZipFolder = Join-Path $TempPath " tSQLt"
23- # $SetupFile = Join-Path $ZipFolder "PrepareServer.sql" # Used in latest version after 1.0.5873.27393
24- $SetupFile = Join-Path $ZipFolder " SetClrEnabled.sql"
2521$InstallFile = Join-Path $ZipFolder " tSQLt.class.sql"
2622$CreateDbQuery = " CREATE DATABASE [tSQLt];"
23+ $SetupFile = Join-Path $ZipFolder " PrepareServer.sql"
2724$CLRSecurityQuery = "
2825/* Turn off CLR Strict for 2017+ fix */
2926IF EXISTS (SELECT 1 FROM sys.configurations WHERE name = 'clr strict security')
@@ -36,36 +33,40 @@ BEGIN
3633END
3734GO"
3835
39-
40- # Download
41- Try {
42- Invoke-WebRequest - Uri $DownloadUrl - OutFile $ZipFile - ErrorAction Stop - UseBasicParsing
43- Expand-Archive - Path $ZipFile - DestinationPath $ZipFolder - Force
44- }
45-
46- Catch {
47- Write-Error - Message " Error downloading tSQLt - try manually fetching from $DownloadUrl "
48- }
49-
5036$Hash = @ {
5137 SqlInstance = $SqlInstance
5238 Database = $Database
5339 EnableException = $true
5440}
5541
56- # Setup
42+ # Cant use latest for AzureSQL yet
43+ # https://github.com/LowlyDBA/dba-multitool/issues/165
5744If ($IsAzureSQL ) {
45+ $Version = " 1-0-5873-27393"
46+ $DownloadUrl = $DownloadUrl + $Version
47+
48+ # Azure creds
5849 $SecPass = ConvertTo-SecureString - String $Pass - AsPlainText - Force
5950 $Credential = New-Object - TypeName System.Management.Automation.PSCredential - ArgumentList $User , $SecPass
6051 $Hash.add (" SqlCredential" , $Credential )
6152}
6253
63- Else {
54+ # Download
55+ Try {
56+ Invoke-WebRequest - Uri $DownloadUrl - OutFile $ZipFile - ErrorAction Stop - UseBasicParsing
57+ Expand-Archive - Path $ZipFile - DestinationPath $ZipFolder - Force
58+ }
59+
60+ Catch {
61+ Write-Error - Message " Error downloading tSQLt - try manually fetching from $DownloadUrl "
62+ }
63+
64+ # Prep
65+ If (-not $IsAzureSQL ) {
6466 Invoke-DbaQuery - SqlInstance $SqlInstance - Database " master" - Query $CreateDbQuery
65- # DbaQuery doesn't play nice with the setup script GOs - default back to sqlcmd
6667 Invoke-Command - ScriptBlock { sqlcmd - S $SqlInstance - d $Database - i $SetupFile } | Out-Null
6768 Invoke-DbaQuery @Hash - Query $CLRSecurityQuery
6869}
6970
7071# Install
71- Invoke-DbaQuery @Hash - File $InstallFile
72+ Invoke-DbaQuery @Hash - File $InstallFile - Verbose
0 commit comments