Skip to content

Commit cdfcf8a

Browse files
authored
Merge pull request #122 from Icinga:feature/mssql_instance_name_fetching
Feature: Adds fetching for MSSQL instance name Adds Cmdlet to fetch instance name of a database we are connected to
2 parents 2863f0e + e0fc750 commit cdfcf8a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function Get-IcingaMSSQLInstanceName()
2+
{
3+
param (
4+
$SqlConnection = $null,
5+
[string]$Username,
6+
[securestring]$Password,
7+
[string]$Address = "localhost",
8+
[int]$Port = 1433,
9+
[switch]$IntegratedSecurity = $FALSE,
10+
[switch]$TestConnection = $FALSE
11+
);
12+
13+
[bool]$NewSqlConnection = $FALSE;
14+
15+
if ($null -eq $SqlConnection) {
16+
$SqlConnection = Open-IcingaMSSQLConnection -Username $Username -Password $Password -Address $Address -IntegratedSecurity:$IntegratedSecurity -Port $Port -TestConnection:$TestConnection;
17+
18+
if ($null -eq $SqlConnection) {
19+
return 'Unknown';
20+
}
21+
22+
$NewSqlConnection = $TRUE;
23+
}
24+
25+
$Query = 'SELECT @@servicename'
26+
$SqlCommand = New-IcingaMSSQLCommand -SqlConnection $SqlConnection -SqlQuery $Query;
27+
$InstanceName = (Send-IcingaMSSQLCommand -SqlCommand $SqlCommand).Column1;
28+
29+
if ($NewSqlConnection -eq $TRUE) {
30+
Close-IcingaMSSQLConnection -SqlConnection $SqlConnection;
31+
}
32+
33+
return $InstanceName;
34+
}

0 commit comments

Comments
 (0)