mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
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
This commit is contained in:
commit
cdfcf8af49
1 changed files with 34 additions and 0 deletions
34
lib/mssql/Get-IcingaMSSQLInstanceName.psm1
Normal file
34
lib/mssql/Get-IcingaMSSQLInstanceName.psm1
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
function Get-IcingaMSSQLInstanceName()
|
||||
{
|
||||
param (
|
||||
$SqlConnection = $null,
|
||||
[string]$Username,
|
||||
[securestring]$Password,
|
||||
[string]$Address = "localhost",
|
||||
[int]$Port = 1433,
|
||||
[switch]$IntegratedSecurity = $FALSE,
|
||||
[switch]$TestConnection = $FALSE
|
||||
);
|
||||
|
||||
[bool]$NewSqlConnection = $FALSE;
|
||||
|
||||
if ($null -eq $SqlConnection) {
|
||||
$SqlConnection = Open-IcingaMSSQLConnection -Username $Username -Password $Password -Address $Address -IntegratedSecurity:$IntegratedSecurity -Port $Port -TestConnection:$TestConnection;
|
||||
|
||||
if ($null -eq $SqlConnection) {
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
$NewSqlConnection = $TRUE;
|
||||
}
|
||||
|
||||
$Query = 'SELECT @@servicename'
|
||||
$SqlCommand = New-IcingaMSSQLCommand -SqlConnection $SqlConnection -SqlQuery $Query;
|
||||
$InstanceName = (Send-IcingaMSSQLCommand -SqlCommand $SqlCommand).Column1;
|
||||
|
||||
if ($NewSqlConnection -eq $TRUE) {
|
||||
Close-IcingaMSSQLConnection -SqlConnection $SqlConnection;
|
||||
}
|
||||
|
||||
return $InstanceName;
|
||||
}
|
||||
Loading…
Reference in a new issue