From ee8d71d3f19d75177db021562dfdef984c9513c7 Mon Sep 17 00:00:00 2001 From: Jorge Henrique Nunes de Vasconcelos Date: Mon, 4 Feb 2019 15:02:16 -0300 Subject: [PATCH] Changed output for connection errors and no instances found --- Get-MSSQLLinkPasswords.psm1 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Get-MSSQLLinkPasswords.psm1 b/Get-MSSQLLinkPasswords.psm1 index 1177f63..f5b46d1 100644 --- a/Get-MSSQLLinkPasswords.psm1 +++ b/Get-MSSQLLinkPasswords.psm1 @@ -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 @@ -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") {