Remove-TwilioQueue.ps1

function Remove-TwilioQueue
{
    <#
    .Synopsis
        Removes a Twilio Queue
    .Description
        Removes a Queue from Twilio
    .Example
        Remove-TwilioQueue
 
    #>

    [CmdletBinding(SupportsShouldProcess=$true)]
    [OutputType([Nullable])]
    param(
    [Parameter(Mandatory=$true,ParameterSetName = 'RemoveBysid', ValueFromPipelineByPropertyName=$true)]
    [string]
    $Sid,

    [Parameter(Mandatory=$true,ParameterSetName = 'RemoveByName', Position=0)]
    [string]
    $Name,

    # The Twilio credential
    [Parameter(ValueFromPipelineByPropertyName=$true)]       
    [Management.Automation.PSCredential]
    $Credential,

    # Twilio connection settings
    [Parameter(ValueFromPipelineByPropertyName=$true)]       
    [string[]]
    $Setting = @("TwilioAccountKey", "TwilioAccountSecret")


    )

    process {
        if (-not $Credential -and $Setting) {
            if ($setting.Count -eq 1) {

                $userName = Get-WebConfigurationSetting -Setting "${Setting}_UserName"
                $password = Get-WebConfigurationSetting -Setting "${Setting}_Password"
            } elseif ($setting.Count -eq 2)  {
                $userName = Get-secureSetting -Name $Setting[0] -ValueOnly
                $password= Get-secureSetting -Name $Setting[1] -ValueOnly
            }

            if ($userName -and $password) {                
                $password = ConvertTo-SecureString -AsPlainText -Force $password
                $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)
            }
            
            
        }
        
        if (-not $Credential) {
            Write-Error "No Twilio Credential provided. Use -Credential or Set-TwilioCredential first"               
            return
        }
            

        if ($PSCmdlet.ParameterSetName -eq 'RemoveByName') {
            $sid = Get-TwilioQueue -Name $Name -Credential $Credential | Select-Object -ExpandProperty Sid
        }

        $getWebParams = @{
            WebCredential=$credential
            Url="https://api.twilio.com/2010-04-01/Accounts/$($Credential.GetNetworkCredential().Username.Trim())/Queues/$Sid"
            METHOD = "DELETE"    
            AsXml =$true
            UseWebRequest = $true
            
        }

        
        if ($PSCmdlet.ShouldProcess("Remove Call Queue $sid")) {
            Get-Web @getWebParams
        }



    }
}