functions/Get-DBODefaultSetting.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
50
51
52
53
54
55
function Get-DBODefaultSetting {
    <#
        .SYNOPSIS
            Retrieves default configuration elements by name.
 
        .DESCRIPTION
            Retrieves default configuration elements by name.
            Can be used to search the existing defaults list.
 
        .PARAMETER Name
            Default: "*"
            The name of the configuration element(s) to retrieve.
            May be any string, supports wildcards.
 
        .PARAMETER Force
            Overrides the default behavior and also displays hidden configuration values.
         
        .PARAMETER Value
            Extracts the value instead of returning the configuration object.
        .NOTES
 
        .EXAMPLE
            PS C:\> Get-DBODefaultSetting 'ExecutionTimeout'
 
            Retrieves the configuration element for the key "ExecutionTimeout"
 
        .EXAMPLE
            PS C:\> Get-DBODefaultSetting -Force
 
            Retrieve all configuration elements from the module, even hidden ones.
    #>

    [CmdletBinding(DefaultParameterSetName = "FullName")]
    Param (
        [Parameter(ParameterSetName = "FullName", Position = 0)]
        [Alias("FullName")]
        [string[]]$Name = "*",
        [switch]$Force,
        [switch]$Value
    )
    switch ($Value) {
        $true {
            if ($Name.count -gt 1) {
                Write-PSFMessage -Level Warning -Message "Provide a single item when requesting a value"
                return
            }
            Get-PSFConfigValue -FullName "dbops.$Name"
        }
        $false {
            foreach ($n in $Name) {
                Get-PSFConfig -Module dbops -Name $n -Force:$Force | Select-Object @{ Name = "Name"; Expression = {$_.FullName -replace '^dbops\.', '' } }, Value, Description
            }
        }
    }
}