mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Adds support to test MSSQL connections
This commit is contained in:
parent
cdfcf8af49
commit
10d94690a8
1 changed files with 10 additions and 1 deletions
|
|
@ -25,6 +25,9 @@
|
||||||
the user the PowerShell is running with. If this is set and the user the PowerShell is
|
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
|
running with can access to the MSSQL database you will not require to provide username
|
||||||
and password
|
and password
|
||||||
|
.PARAMETER TestConnection
|
||||||
|
Set this if you want to return $null on connection errors during MSSQL.open() instead of
|
||||||
|
exception messages.
|
||||||
.OUTPUTS
|
.OUTPUTS
|
||||||
System.Data.SqlClient.SqlConnection
|
System.Data.SqlClient.SqlConnection
|
||||||
.LINK
|
.LINK
|
||||||
|
|
@ -38,7 +41,8 @@ function Open-IcingaMSSQLConnection()
|
||||||
[string]$Address = "localhost",
|
[string]$Address = "localhost",
|
||||||
[int]$Port = 1433,
|
[int]$Port = 1433,
|
||||||
[string]$SqlDatabase,
|
[string]$SqlDatabase,
|
||||||
[switch]$IntegratedSecurity = $FALSE
|
[switch]$IntegratedSecurity = $FALSE,
|
||||||
|
[switch]$TestConnection = $FALSE
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($IntegratedSecurity -eq $FALSE) {
|
if ($IntegratedSecurity -eq $FALSE) {
|
||||||
|
|
@ -80,6 +84,11 @@ function Open-IcingaMSSQLConnection()
|
||||||
|
|
||||||
$SqlConnection.Open();
|
$SqlConnection.Open();
|
||||||
} catch {
|
} catch {
|
||||||
|
|
||||||
|
if ($TestConnection) {
|
||||||
|
return $null;
|
||||||
|
}
|
||||||
|
|
||||||
Exit-IcingaThrowException `
|
Exit-IcingaThrowException `
|
||||||
-InputString $_.Exception.Message `
|
-InputString $_.Exception.Message `
|
||||||
-StringPattern $Username `
|
-StringPattern $Username `
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue