Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Send SMS/Text Message via Twillo
function Send-TextNotification {
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
try {
# Send Message
$body = @{Body = $msg; To = $to; From = $from;}
$result = Invoke-RestMethod -Method Post -Uri "$($accountSID)/Messages.json" -Body $body -Credential $auth -UseBasicParsing
if ($result.sid) {
Write-host -ForegroundColor green "Message to: $($ is $($result.status)"
} catch {
Write-Error "Failed to send Notification. ErrorCode: $($_.Exception.Response.StatusCode.value__) ErrorDetails: $($_.Exception.Response.StatusDetails) ErrorDescription: $($_.Exception.Response.StatusDescription)"
# TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Twillo Account SID
$accountSID = "yourTwilloAccountSID"
# Twillo Account Token
$accountToken = "yourTwilloAccountToken"
# Basic Auth
$p = $accountToken | ConvertTo-SecureString -asPlainText -Force
$auth = New-Object System.Management.Automation.PSCredential($accountSID, $p)
# To
[string]$to = '+DestinationMobileNumber'
# From
[string]$from = '+TwilloAccountMobileNumber'
# Message
[string]$msg = "Everything is on fire. Investigate and Remediate immediately!!"
Send-TextNotification -from $from -to $to -auth $auth -msg $msg -accountSID $accountSID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.