Skip to content

Commit

Permalink
✨🔒️ Secure password value; return false if connection fails
Browse files Browse the repository at this point in the history
  • Loading branch information
brianary committed Nov 15, 2023
1 parent b354f2e commit 4c32ce9
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Test-ConnectionString.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,24 @@ LocalSMOVersion : 17.100.0.0
)
Process
{
$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 @'
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 @'
select @@ServerName [ServerName], db_name() [DatabaseName],
serverproperty('ComputerNamePhysicalNetBIOS') [ComputerName],
serverproperty('MachineName') [MachineName],
serverproperty('InstanceName') [InstanceName],
current_timestamp [ServerTime],
serverproperty('Edition') [Edition],
app_name() [AppName];
'@ |Add-Member -NotePropertyName Server -NotePropertyValue $server -PassThru |
ConvertTo-OrderedDictionary.ps1
return [pscustomobject](Join-Keys.ps1 $conn $info)
'@ |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)
}
catch {return $false}
}

0 comments on commit 4c32ce9

Please sign in to comment.