Public/Get-SurveyDefinitions.ps1

<#
    .SYNOPSIS
    Query salesforce for all survey definitions

    .DESCRIPTION
    Queries for all the surveys, questions and answers

    .INPUTS
    None. You cannot pipe objects to Get-SurveyDefinitions.

    .OUTPUTS
    An PSCustomObject containing the following members:
        answers
        surveys
        questions

    The 'answers' key contains an array of PSCustomObject with the following members:
        Id
        phecc__Answer__c
        phecc__Survey_Question__c

    The 'surveys' key contains an array of PSCustomObject with the following members:
        Id
        Name

    The 'questions' key contains an array of PSCustomObject with the following members:
        Id
        phecc__Question__c
        phecc__Survey__c

    .EXAMPLE
    PS> $surveyDefs = Get-SurveyDefinitions

    .LINK
    Set-Config

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

function Get-SurveyDefinitions {

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param()

    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)"
        Write-Verbose "Reading Org Survey Metadata"
        @{
            surveys   = (invoke-sfquery "SELECT Id,Name FROM phecc__Survey__c WHERE IsDeleted = false AND phecc__Status__c = 'Published'")
            questions = (invoke-sfquery "SELECT Id,phecc__Question__c,phecc__Survey__c FROM phecc__Survey_Question__c")
            answers   = (invoke-sfquery "SELECT Id,phecc__Answer__c,phecc__Survey_Question__c FROM phecc__Survey_Answer__c")
        }
    }
}