Skip to content

Commit 74eafd1

Browse files
author
devizer
committed
Module: Query SQL Title
1 parent ac0f129 commit 74eafd1

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

Install-SqlServer-Version-Management.ps1

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Param(
44
)
55

66
$ModuleName = 'SqlServer-Version-Management';
7-
$ModuleVersion = '2.1.190';
7+
$ModuleVersion = '2.1.191';
88
$ModuleFiles = @(
99
@{
1010
FileName = 'SqlServer-Version-Management\SqlServer-Version-Management.psd1';
@@ -15,7 +15,7 @@ $ModuleFiles = @(
1515
" ModuleToProcess = @('SqlServer-Version-Management.psm1')",
1616
"",
1717
" # Version below is automatically incremented on build",
18-
" ModuleVersion = `"2.1.190`"",
18+
" ModuleVersion = `"2.1.191`"",
1919
"",
2020
" GUID = 'dd03b53d-575a-4056-ae08-e6dfea3384ea'",
2121
"",
@@ -2395,7 +2395,7 @@ $ModuleFiles = @(
23952395
" `$ansiValue = `$ansiColors[`$key];",
23962396
" `$ansi += `$ansiValue;",
23972397
" `$isReset = (`$key -eq `"Reset`");",
2398-
" if (`$isReset) { `$text=`"Gray`"; `$back=`"Black`"; }",
2398+
" if (`$isReset) { `$text=`"Gray`"; `$back=`"Black`"; <# `$ansi += `$ansiColors[`"Reset`"] #> }",
23992399
" if (`$key -like `"Text*`") { `$text = `$key.SubString(4) }",
24002400
" if (`$key -like `"Back*`") { `$back = `$key.SubString(4) }",
24012401
" `$isControl = `$true;",
@@ -3866,7 +3866,7 @@ $ModuleFiles = @(
38663866
"}",
38673867
"",
38683868
"# Include File: [\Includes.SqlServer\Query-SqlServer-Version.ps1]",
3869-
"function Query-SqlServer-Version([string] `$title, [string] `$connectionString, <# or #>[string] `$instance, [int] `$timeoutSec = 30) {",
3869+
"function Query-SqlServer-Version([string] `$title, [string] `$connectionString, <# or #>[string] `$instance, [int] `$timeoutSec = 30, [string] `$kind = `"Medium`" <# or Title #>) {",
38703870
" if (-not `$connectionString) { `$connectionString = `"Server=`$(`$instance);Integrated Security=SSPI;Connection Timeout=3;Pooling=False`" }",
38713871
" `$startAt = [System.Diagnostics.Stopwatch]::StartNew();",
38723872
" `$exception = `$null;",
@@ -3881,6 +3881,9 @@ $ModuleFiles = @(
38813881
"Cast(ISNULL(ServerProperty('ProductUpdateLevel'), '') as nvarchar(222)) + ",
38823882
"(Case ServerProperty('IsFullTextInstalled') When 1 Then ' + Full-text' Else '' End);",
38833883
"`"@;",
3884+
" if (`$kind -eq `"Title`") {",
3885+
" `$sql = `"SET NOCOUNT ON; Declare @ret nvarchar(1000); SELECT @ret = CAST(LEFT(@@VERSION, CHARINDEX(CHAR(10), @@VERSION) - 1) AS NVARCHAR(MAX)) + (Case ServerProperty('IsLocalDB') When 1 Then 'LocalDB' Else '' End) + ' ' + Cast(ISNULL(ServerProperty('Edition'), '') as nvarchar(222)) + ' ' + Cast(ISNULL(ServerProperty('ProductLevel'), '') as nvarchar(222)) + ' ' + Cast(ISNULL(ServerProperty('ProductUpdateLevel'), '') as nvarchar(222)); Set @ret = Replace(@ret, ' ', ' '); Set @ret = Replace(@ret, ' ', ' '); Select @ret;`"",
3886+
" }",
38843887
" `$con = New-Object System.Data.SqlClient.SqlConnection(`$connectionString);",
38853888
" `$con.Open();",
38863889
" `$cmd = new-object System.Data.SqlClient.SqlCommand(`$sql, `$con)",
@@ -3894,7 +3897,6 @@ $ModuleFiles = @(
38943897
" } catch { `$exception = `$_.Exception; <# Write-Host `$_.Exception -ForegroundColor DarkGray #> }",
38953898
" } while(`$startAt.ElapsedMilliseconds -le (`$timeoutSec * 1000));",
38963899
" Write-Host `"Warning! Can't query version of SQL Server '`$(`$title)' during `$(`$startAt.ElapsedMilliseconds / 1000) seconds`$([Environment]::NewLine)`$(`$exception)`" -ForegroundColor DarkRed",
3897-
"",
38983900
"}",
38993901
"",
39003902
"# Query-SqlServer-Version -Title `"FAKE`" -Instance `"(local)\22`" -Timeout 2",

SqlServer-Version-Management.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,7 +2262,7 @@ Function Write-Line([string[]] $directArgs = @()) {
22622262
$ansiValue = $ansiColors[$key];
22632263
$ansi += $ansiValue;
22642264
$isReset = ($key -eq "Reset");
2265-
if ($isReset) { $text="Gray"; $back="Black"; }
2265+
if ($isReset) { $text="Gray"; $back="Black"; <# $ansi += $ansiColors["Reset"] #> }
22662266
if ($key -like "Text*") { $text = $key.SubString(4) }
22672267
if ($key -like "Back*") { $back = $key.SubString(4) }
22682268
$isControl = $true;
@@ -3733,7 +3733,7 @@ function Publish-SQLServer-SetupLogs([string] $toFolder, $compression=9) {
37333733
}
37343734

37353735
# Include File: [\Includes.SqlServer\Query-SqlServer-Version.ps1]
3736-
function Query-SqlServer-Version([string] $title, [string] $connectionString, <# or #>[string] $instance, [int] $timeoutSec = 30) {
3736+
function Query-SqlServer-Version([string] $title, [string] $connectionString, <# or #>[string] $instance, [int] $timeoutSec = 30, [string] $kind = "Medium" <# or Title #>) {
37373737
if (-not $connectionString) { $connectionString = "Server=$($instance);Integrated Security=SSPI;Connection Timeout=3;Pooling=False" }
37383738
$startAt = [System.Diagnostics.Stopwatch]::StartNew();
37393739
$exception = $null;
@@ -3748,6 +3748,9 @@ Cast(ISNULL(ServerProperty('ProductLevel'), '') as nvarchar(222)) + ' ' +
37483748
Cast(ISNULL(ServerProperty('ProductUpdateLevel'), '') as nvarchar(222)) +
37493749
(Case ServerProperty('IsFullTextInstalled') When 1 Then ' + Full-text' Else '' End);
37503750
"@;
3751+
if ($kind -eq "Title") {
3752+
$sql = "SET NOCOUNT ON; Declare @ret nvarchar(1000); SELECT @ret = CAST(LEFT(@@VERSION, CHARINDEX(CHAR(10), @@VERSION) - 1) AS NVARCHAR(MAX)) + (Case ServerProperty('IsLocalDB') When 1 Then 'LocalDB' Else '' End) + ' ' + Cast(ISNULL(ServerProperty('Edition'), '') as nvarchar(222)) + ' ' + Cast(ISNULL(ServerProperty('ProductLevel'), '') as nvarchar(222)) + ' ' + Cast(ISNULL(ServerProperty('ProductUpdateLevel'), '') as nvarchar(222)); Set @ret = Replace(@ret, ' ', ' '); Set @ret = Replace(@ret, ' ', ' '); Select @ret;"
3753+
}
37513754
$con = New-Object System.Data.SqlClient.SqlConnection($connectionString);
37523755
$con.Open();
37533756
$cmd = new-object System.Data.SqlClient.SqlCommand($sql, $con)
@@ -3761,7 +3764,6 @@ Cast(ISNULL(ServerProperty('ProductUpdateLevel'), '') as nvarchar(222)) +
37613764
} catch { $exception = $_.Exception; <# Write-Host $_.Exception -ForegroundColor DarkGray #> }
37623765
} while($startAt.ElapsedMilliseconds -le ($timeoutSec * 1000));
37633766
Write-Host "Warning! Can't query version of SQL Server '$($title)' during $($startAt.ElapsedMilliseconds / 1000) seconds$([Environment]::NewLine)$($exception)" -ForegroundColor DarkRed
3764-
37653767
}
37663768

37673769
# Query-SqlServer-Version -Title "FAKE" -Instance "(local)\22" -Timeout 2

0 commit comments

Comments
 (0)