Public/Get-SfApiVersions.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
<#
    .SYNOPSIS
    Queries salesforce for the REST API Versions

    .DESCRIPTION
    Used to query for the REST API versions

    .INPUTS
    Accepts the API name from the pipeline

    .OUTPUTS
    An array of PSCustomObject with the properties:
        Id
        phecc__ApiName__c
        phecc__ClassName__c
        phecc__Version__c

    .EXAMPLE
    PS> $versions = Get-SfApiVersions -ApiName "ScalarRest"

    .LINK
    Set-Config

    .NOTES
    Assumes config is initialized for org access.
#>

function Get-SfApiVersions {

    [CmdletBinding()]
    [OutputType([PSCustomObject[]])]
    param(
        [Parameter(Mandatory = $false, Position = 0, ValueFromPipeline)]
        [ValidateNotNull()]
        [String]
        $ApiName
    )

    begin {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"
    }

    end {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete"
    }

    process {
        Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"

        $query = "SELECT phecc__ApiName__c,phecc__ClassName__c,phecc__Version__c FROM phecc__RestAPIVersions__c"
        if ($PSBoundParameters.ContainsKey('ApiName')) {
            $query += " WHERE phecc__ApiName__c = '$($ApiName)'"
        }
        Invoke-SfQuery $query
    }
}