Skip to content

Commit

Permalink
Changed output for connection errors and no instances found
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Henrique Nunes de Vasconcelos committed Feb 4, 2019
1 parent 50c14be commit ee8d71d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Get-MSSQLLinkPasswords.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ function Get-MSSQLLinkPasswords{

# Set local computername and get all SQL Server instances
$ComputerName = $Env:computername
$SqlInstances = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server' -Name InstalledInstances).InstalledInstances

$SqlInstances = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server' -Name InstalledInstances -ErrorAction SilentlyContinue).InstalledInstances
if($null -eq $SqlInstances) {
Write-Output "`nNo instances were found on [$ComputerName]`n"
}
$Results = New-Object "System.Data.DataTable"
$Results.Columns.Add("Instance") | Out-Null
$Results.Columns.Add("Linkserver") | Out-Null
Expand Down Expand Up @@ -73,7 +75,9 @@ function Get-MSSQLLinkPasswords{

Try{$Conn.Open();}
Catch{
Write-Error "Error creating DAC connection: $_.Exception.Message"
$errorMessage = "Error creating DAC connection:`n "+$_.Exception.Message
$errorMessage = $errorMessage + "`nAttemped to connect using`n$ConnString`n"
Write-Error -Category ConnectionError $errorMessage
Continue
}
if ($Conn.State -eq "Open") {
Expand Down

0 comments on commit ee8d71d

Please sign in to comment.