Public/Invoke-SfQuery.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
<#
    .SYNOPSIS
    Execute a SOQL statement in the configured Salesforce org

    .DESCRIPTION
    Execute a SOQL statement in the configured Salesforce org

    .INPUTS
    None. You cannot pipe objects to Invoke-SfQuery.

    .OUTPUTS
    The result of the SOQL query.

    .PARAMETER Query
    The SOQL statement to execute

    .EXAMPLE
    PS> $AccountNames = Invoke-SfQuery "SELECT Name FROM Account" | Select Name

    .LINK
    Set-FileConfig

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

function Invoke-SfQuery {
    param([String]$Query)
    $q = $Query -replace " ","+"
    (Invoke-SfApi "/query?q=$($q)").records
}