From 10d94690a8c1e6b19a7ac4abfb277d712594f167 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Fri, 28 Aug 2020 13:14:51 +0200 Subject: [PATCH] Adds support to test MSSQL connections --- lib/mssql/Open-IcingaMSSQLConnection.psm1 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/mssql/Open-IcingaMSSQLConnection.psm1 b/lib/mssql/Open-IcingaMSSQLConnection.psm1 index 9e437d4..6ad61f3 100644 --- a/lib/mssql/Open-IcingaMSSQLConnection.psm1 +++ b/lib/mssql/Open-IcingaMSSQLConnection.psm1 @@ -25,6 +25,9 @@ the user the PowerShell is running with. If this is set and the user the PowerShell is running with can access to the MSSQL database you will not require to provide username and password +.PARAMETER TestConnection + Set this if you want to return $null on connection errors during MSSQL.open() instead of + exception messages. .OUTPUTS System.Data.SqlClient.SqlConnection .LINK @@ -38,7 +41,8 @@ function Open-IcingaMSSQLConnection() [string]$Address = "localhost", [int]$Port = 1433, [string]$SqlDatabase, - [switch]$IntegratedSecurity = $FALSE + [switch]$IntegratedSecurity = $FALSE, + [switch]$TestConnection = $FALSE ); if ($IntegratedSecurity -eq $FALSE) { @@ -80,6 +84,11 @@ function Open-IcingaMSSQLConnection() $SqlConnection.Open(); } catch { + + if ($TestConnection) { + return $null; + } + Exit-IcingaThrowException ` -InputString $_.Exception.Message ` -StringPattern $Username `