Get-TwilioTranscription.ps1

function Get-TwilioTranscription
{
    <#
    .Synopsis
        Gets Twilio call Transcriptions
    .Description
        Get Transcriptions from Twilio calls
    .Example
        Get-TwilioTranscription
    .Link
        Twilio.com
    .Link
        Get-PhoneCall
    #>


    param(    
    # The credential used to get the texts
    [Parameter(ValueFromPipelineByPropertyName=$true)]
    [Management.Automation.PSCredential]
    $Credential,
    
    
    # A setting storing the credential
    [Parameter(ValueFromPipelineByPropertyName=$true)]   
    [string]
    $Setting = "TwilioAccountDefault",
    
    # A call SID
    [Parameter(ValueFromPipelineByPropertyName=$true)]   
    [string]
    $RecordingSid
    
    
    )
    
    process {
        #region Fetch Credential
        if (-not $Credential -and $Setting) {
            $userName = Get-WebConfigurationSetting -Setting "${Setting}_UserName"
            $password = Get-WebConfigurationSetting -Setting "${Setting}_Password"
            
            if ($userName -and $password) {
                $password = Get-WebConfigurationSetting -Setting "${Setting}_Password" |
                    ConvertTo-SecureString -AsPlainText -Force           
                $credential  = New-Object Management.Automation.PSCredential $username, $password 
            } elseif ((Get-SecureSetting -Name "$Setting" -ValueOnly | Select-Object -First 1)) {
                $credential = (Get-SecureSetting -Name "$Setting" -ValueOnly | Select-Object -First 1)
            }
            
            
        }
        #endregion
        
        #region Get Transcriptions
        if (-not $Credential) {
            Write-Error "No Twilio Credential provided. Use -Credential or Add-SecureSetting TwilioAccountDefault -Credential (Get-Credential) first"               
            return
        }

        $getWebParams = @{
            WebCredential=$Credential
            Url="https://api.twilio.com/2010-04-01/Accounts/$($Credential.GetNetworkCredential().Username.Trim())/Transcriptions"           
            AsXml =$true            
            UseWebRequest = $true
        }        
        $twiResponse = Get-Web @getwebParams  |            
            Select-Object -ExpandProperty TwilioResponse 
            
        if ($twiResponse.Transcriptions) {
            $twiResponse.Transcriptions | 
                Select-Object -ExpandProperty Transcription |
                Where-Object { 
                    if ($RecordingSid) {
                        $_.RecordingSid -eq $recordingSid
                    } else {
                        $true
                    }
                } |
                ForEach-Object {                    
                        $_
                }
        }
        #endregion Get Transcriptions
              
    }       

}