public/Get-GzDbConnectionString.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

function Get-GzDbConnectionString() {
    <#
        .SYNOPSIS
        Gets the default global connection string
     
        .DESCRIPTION
        This function is called in absense of a specified connection string
        for functions that require them.
     
        .PARAMETER Name
        Optional. The name of the connection string to retrieve. If the name is not specified,
        the name defaults to 'Default'.
     
        .EXAMPLE
        $connectionString = Get-DbConnectionString
     
        .EXAMPLE
        $connectionString = Get-DbConnectionString -Name "MySql"
    #>

        [CmdletBinding()]
        Param(
    
    
        )
    
        DynamicParam {
            $runtimeParameters  = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
            $providerNameAttr  = New-Object System.Management.Automation.ParameterAttribute
            $providerNameAttr.Mandatory  = $false 
            $providerNameAttr.Position = 0
            $providerNameAttr.ParameterSetName  = '__AllParameterSets'
            $providerNameAttrs = New-Object  System.Collections.ObjectModel.Collection[System.Attribute]
            $providerNameAttrs.Add($providerNameAttr)
            $connectionStrings = Get-GzDbOption -Name "ConnectionStrings"
            $keys = $connectionStrings.Keys 
            $providerNameAttrs.Add((New-Object  System.Management.Automation.ValidateSetAttribute($keys)));
            $providerName = New-Object System.Management.Automation.RuntimeDefinedParameter("Name", [String], $providerNameAttrs)        
            $runtimeParameters.Add("Name", $providerName)            
    
            return $runtimeParameters;
        }
    
        Process {
            $Name = $PSBoundParameters["Name"];
            if(!$Name) { $Name = "Default" }
            return Get-GzDbOption -Name "ConnectionStrings/$Name" 
        }
    }