diff --git a/Test-ConnectionString.ps1 b/Test-ConnectionString.ps1 index 5b871281..1819fa41 100644 --- a/Test-ConnectionString.ps1 +++ b/Test-ConnectionString.ps1 @@ -9,7 +9,7 @@ System.Management.Automation.PSObject containing properties about the connection Database .EXAMPLE -Test-ConnectionString.ps1 'Server=(localdb)\ProjectsV13;Integrated Security=SSPI;Encrypt=True' +Test-ConnectionString.ps1 'Server=(localdb)\ProjectsV13;Integrated Security=SSPI;Encrypt=True' -Details ServerName : SERVERNAME\LOCALDB#DCCC9EEC AppName : Core Microsoft SqlClient Data Provider @@ -48,17 +48,20 @@ LocalSMOVersion : 17.100.0.0 #Requires -Version 3 #Requires -Modules dbatools [CmdletBinding()][OutputType([psobject])] Param( -[Parameter(Position=0,Mandatory=$true)][string] $ConnectionString +[Parameter(Position=0,Mandatory=$true)][string] $ConnectionString, +[switch] $Details ) Process { try { - $csb = New-DbaConnectionStringBuilder -ConnectionString $ConnectionString - $server = Connect-DbaInstance -ConnectionString $ConnectionString - $conn = Join-Keys.ps1 -ReferenceObject (New-Object Collections.Hashtable $csb) ` - -InputObject (Test-DbaConnection $csb.DataSource -SkipPSRemoting |ConvertTo-OrderedDictionary.ps1) - $info = Invoke-DbaQuery -SqlInstance $server -As PSObject -Query @' + if($Details) + { + $csb = New-DbaConnectionStringBuilder -ConnectionString $ConnectionString + $server = Connect-DbaInstance -ConnectionString $ConnectionString + $conn = Join-Keys.ps1 -ReferenceObject (New-Object Collections.Hashtable $csb) ` + -InputObject (Test-DbaConnection $csb.DataSource -SkipPSRemoting |ConvertTo-OrderedDictionary.ps1) + $info = Invoke-DbaQuery -SqlInstance $server -As PSObject -Query @' select @@ServerName [ServerName], db_name() [DatabaseName], serverproperty('ComputerNamePhysicalNetBIOS') [ComputerName], serverproperty('MachineName') [MachineName], @@ -67,9 +70,15 @@ select @@ServerName [ServerName], db_name() [DatabaseName], serverproperty('Edition') [Edition], app_name() [AppName]; '@ |ConvertTo-OrderedDictionary.ps1 - if($info.ContainsKey('Password')) {$info['Password'] = ConvertTo-SecureString $info['Password'] -AsPlainText -Force} - [void] $info.Add('Server', $server) - return [pscustomobject](Join-Keys.ps1 $conn $info) + if($info.ContainsKey('Password')) {$info['Password'] = ConvertTo-SecureString $info['Password'] -AsPlainText -Force} + [void] $info.Add('Server', $server) + return [pscustomobject](Join-Keys.ps1 $conn $info) + } + else + { + return Invoke-DbaQuery -SqlInstance (Connect-DbaInstance -ConnectionString $ConnectionString) ` + -Query 'select cast(1 as bit) Success;' |ConvertFrom-DataRow.ps1 -AsValues + } } catch {return $false} }