@@ -14,16 +14,12 @@ 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"
26- $CreateDbQuery = " CREATE DATABASE [tSQLt]; "
22+ $SetupFile = Join-Path $ZipFolder " PrepareServer.sql "
2723$CLRSecurityQuery = "
2824/* Turn off CLR Strict for 2017+ fix */
2925IF EXISTS (SELECT 1 FROM sys.configurations WHERE name = 'clr strict security')
@@ -36,36 +32,40 @@ BEGIN
3632END
3733GO"
3834
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-
5035$Hash = @ {
5136 SqlInstance = $SqlInstance
5237 Database = $Database
5338 EnableException = $true
5439}
5540
56- # Setup
41+ # Cant use latest for AzureSQL yet
42+ # https://github.com/LowlyDBA/dba-multitool/issues/165
5743If ($IsAzureSQL ) {
44+ $Version = " 1-0-5873-27393"
45+ $DownloadUrl = $DownloadUrl + $Version
46+
47+ # Azure creds
5848 $SecPass = ConvertTo-SecureString - String $Pass - AsPlainText - Force
5949 $Credential = New-Object - TypeName System.Management.Automation.PSCredential - ArgumentList $User , $SecPass
6050 $Hash.add (" SqlCredential" , $Credential )
6151}
6252
63- Else {
64- Invoke-DbaQuery - SqlInstance $SqlInstance - Database " master" - Query $CreateDbQuery
65- # DbaQuery doesn't play nice with the setup script GOs - default back to sqlcmd
53+ # Download
54+ Try {
55+ Invoke-WebRequest - Uri $DownloadUrl - OutFile $ZipFile - ErrorAction Stop - UseBasicParsing
56+ Expand-Archive - Path $ZipFile - DestinationPath $ZipFolder - Force
57+ }
58+
59+ Catch {
60+ Write-Error - Message " Error downloading tSQLt - try manually fetching from $DownloadUrl "
61+ }
62+
63+ # Prep
64+ If (-not $IsAzureSQL ) {
65+ New-DbaDatabase - SqlInstance $SqlInstance - Database $Database - Recoverymodel Simple | Out-Null
6666 Invoke-Command - ScriptBlock { sqlcmd - S $SqlInstance - d $Database - i $SetupFile } | Out-Null
6767 Invoke-DbaQuery @Hash - Query $CLRSecurityQuery
6868}
6969
7070# Install
71- Invoke-DbaQuery @Hash - File $InstallFile
71+ Invoke-DbaQuery @Hash - File $InstallFile - Verbose
0 commit comments