Skip to content

Commit 0bcb765

Browse files
committed
Changed output for connection errors and no instances found
1 parent 73ef501 commit 0bcb765

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Get-MSSQLLinkPasswords.psm1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ function Get-MSSQLLinkPasswords{
4343

4444
# Set local computername and get all SQL Server instances
4545
$ComputerName = $Env:computername
46-
$SqlInstances = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server' -Name InstalledInstances).InstalledInstances
47-
46+
$SqlInstances = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server' -Name InstalledInstances -ErrorAction SilentlyContinue).InstalledInstances
47+
if($null -eq $SqlInstances) {
48+
Write-Output "`nNo instances were found on [$ComputerName]`n"
49+
}
4850
$Results = New-Object "System.Data.DataTable"
4951
$Results.Columns.Add("Instance") | Out-Null
5052
$Results.Columns.Add("Linkserver") | Out-Null
@@ -73,7 +75,9 @@ function Get-MSSQLLinkPasswords{
7375

7476
Try{$Conn.Open();}
7577
Catch{
76-
Write-Error "Error creating DAC connection: $_.Exception.Message"
78+
$errorMessage = "Error creating DAC connection:`n "+$_.Exception.Message
79+
$errorMessage = $errorMessage + "`nAttemped to connect using`n$ConnString`n"
80+
Write-Error -Category ConnectionError $errorMessage
7781
Continue
7882
}
7983
if ($Conn.State -eq "Open") {

0 commit comments

Comments
 (0)