Private/Endpoint/Get-BDEndPoint.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function Get-BDEndPoint {
    [OutputType([string])]
    [CmdletBinding()]

    <#
    .SYNOPSIS
    Get an endpoint from the collection of endpoint registered in the EndPoints.json file
 
    .DESCRIPTION
    Return an endpoint
 
    .PARAMETER EndPoint
    String containing the name of the endpoint
 
    .PARAMETER EndPointParameters
    Optional hashtable parameter containing the value of the parameter in EndPoint
 
    .INPUTS
 
    None. You cannot pipe objects to Add-Extension.
 
    .OUTPUTS
 
    System.String. Add-Extension returns a string with the extension
    or file name.
 
    .EXAMPLE
 
    PS> extension -name "File"
    File.txt
 
    .EXAMPLE
 
    PS> extension -name "File" -extension "doc"
    File.doc
 
    .EXAMPLE
 
    PS> extension "File" "doc"
    File.doc
 
    #>

    param (
        [Parameter(Mandatory=$true, ValueFromPipeline=$true)] [String] $EndPoint,
        [Parameter(Mandatory=$false)] [Hashtable] $EndPointParameters
    )
    begin {
        $EndPoints = Get-Content "$PSScriptRoot\EndPoints.json" | ConvertFrom-Json
    }
    process {
        # If there are any parameters given, then they are place in the returned string
        if($EndPointParameters) {
            $ReturnValue = $EndPoints.psObject.Properties[$EndPoint].value
            foreach ($key in $EndPointParameters.Keys) {
                $ReturnValue = $ReturnValue -replace "{{$key}}",$EndPointParameters[$key]
            }

        } else {
            $ReturnValue = $EndPoints.psObject.Properties[$EndPoint].value
        }
        if ($ReturnValue -match "{{.+}}") {
            throw [System.NullReferenceException]::new("$($Matches[0]) not supplied!")
        }
        Return $ReturnValue
    }
    end {
    }
}