@@ -9,7 +9,7 @@ System.Management.Automation.PSObject containing properties about the connection
9
9
Database
10
10
11
11
. EXAMPLE
12
- Test-ConnectionString.ps1 'Server=(localdb)\ProjectsV13;Integrated Security=SSPI;Encrypt=True'
12
+ Test-ConnectionString.ps1 'Server=(localdb)\ProjectsV13;Integrated Security=SSPI;Encrypt=True' -Details
13
13
14
14
ServerName : SERVERNAME\LOCALDB#DCCC9EEC
15
15
AppName : Core Microsoft SqlClient Data Provider
@@ -48,17 +48,20 @@ LocalSMOVersion : 17.100.0.0
48
48
# Requires -Version 3
49
49
# Requires -Modules dbatools
50
50
[CmdletBinding ()][OutputType ([psobject ])] Param (
51
- [Parameter (Position = 0 , Mandatory = $true )][string ] $ConnectionString
51
+ [Parameter (Position = 0 , Mandatory = $true )][string ] $ConnectionString ,
52
+ [switch ] $Details
52
53
)
53
54
Process
54
55
{
55
56
try
56
57
{
57
- $csb = New-DbaConnectionStringBuilder - ConnectionString $ConnectionString
58
- $server = Connect-DbaInstance - ConnectionString $ConnectionString
59
- $conn = Join-Keys.ps1 - ReferenceObject (New-Object Collections.Hashtable $csb ) `
60
- - InputObject (Test-DbaConnection $csb.DataSource - SkipPSRemoting | ConvertTo-OrderedDictionary.ps1 )
61
- $info = Invoke-DbaQuery - SqlInstance $server -As PSObject - Query @'
58
+ if ($Details )
59
+ {
60
+ $csb = New-DbaConnectionStringBuilder - ConnectionString $ConnectionString
61
+ $server = Connect-DbaInstance - ConnectionString $ConnectionString
62
+ $conn = Join-Keys.ps1 - ReferenceObject (New-Object Collections.Hashtable $csb ) `
63
+ - InputObject (Test-DbaConnection $csb.DataSource - SkipPSRemoting | ConvertTo-OrderedDictionary.ps1 )
64
+ $info = Invoke-DbaQuery - SqlInstance $server -As PSObject - Query @'
62
65
select @@ServerName [ServerName], db_name() [DatabaseName],
63
66
serverproperty('ComputerNamePhysicalNetBIOS') [ComputerName],
64
67
serverproperty('MachineName') [MachineName],
@@ -67,9 +70,15 @@ select @@ServerName [ServerName], db_name() [DatabaseName],
67
70
serverproperty('Edition') [Edition],
68
71
app_name() [AppName];
69
72
'@ | ConvertTo-OrderedDictionary.ps1
70
- if ($info.ContainsKey (' Password' )) {$info [' Password' ] = ConvertTo-SecureString $info [' Password' ] - AsPlainText - Force}
71
- [void ] $info.Add (' Server' , $server )
72
- return [pscustomobject ](Join-Keys.ps1 $conn $info )
73
+ if ($info.ContainsKey (' Password' )) {$info [' Password' ] = ConvertTo-SecureString $info [' Password' ] - AsPlainText - Force}
74
+ [void ] $info.Add (' Server' , $server )
75
+ return [pscustomobject ](Join-Keys.ps1 $conn $info )
76
+ }
77
+ else
78
+ {
79
+ return Invoke-DbaQuery - SqlInstance (Connect-DbaInstance - ConnectionString $ConnectionString ) `
80
+ - Query ' select cast(1 as bit) Success;' | ConvertFrom-DataRow.ps1 - AsValues
81
+ }
73
82
}
74
83
catch {return $false }
75
84
}
0 commit comments