public/Send-DuoSMS.ps1
|
<#
.Synopsis send duo installation sms .DESCRIPTION .EXAMPLE Send-DuoSMS .EXAMPLE Send-DuoSMS -phone_id .INPUTS [string]phone_id .OUTPUTS [PSCustomObject]DuoRequest .NOTES .COMPONENT PSDuo .FUNCTIONALITY #> function Send-DuoSMS(){ [CmdletBinding()] param( [parameter(Mandatory = $true)] [string]$phone_id, [parameter(Mandatory = $true, ParameterSetName="parameterset01")] [boolean]$installation_msg, [parameter(Mandatory = $true, ParameterSetName="parameterset02")] [boolean]$activation_msg ) [string]$method = "POST" [string]$smstype = '' if($installation_msg -eq $true){ $smstype = 'send_sms_installation' $null = $myinvocation.BoundParameters.Remove('installation_msg') # remove parameter from function parameters because variable apiparams cannot contain an optional parameter with values not accepted from the endpoint. optional parameters cannot be included inside api calls when the value is not meeting api criteria. in our case, we only need it for the sms type }else{ $smstype = 'send_sms_activation' $null = $myinvocation.BoundParameters.Remove('activation_msg') # remove parameter from function parameters because variable apiparams cannot contain an optional parameter with values not accepted from the endpoint. optional parameters cannot be included inside api calls when the value is not meeting api criteria. in our case, we only need it for the sms type } [string]$path = "/admin/v1/phones/$($phone_id)/$($smstype)" $APiParams = $MyInvocation.BoundParameters $DuoRequest = Convertto-DUORequest -DuoMethodPath $path -Method $method -ApiParams $ApiParams $Response = Invoke-RestMethod @DuoRequest -SkipHeaderValidation:$true If ($Response.stat -ne 'OK') { Write-Warning 'DUO REST Call Failed' Write-Warning "APiParams:"+($APiParams | Out-String) Write-Warning "Method:$method Path:$path" } $Output = $Response | Select-Object -ExpandProperty Response Write-Output $Output } |