How to send SMS using PowerShell

In today’s digital age, effective communication is crucial for both personal and professional success. One powerful tool for achieving this is SMS messaging, which allows for quick and direct communication. In this guide, “How to Send SMS Using PowerShell”, I will walk you through the process of leveraging PowerShell and Twilio to send SMS messages efficiently. Whether you’re a seasoned developer or just starting out, this guide will provide you with the knowledge and tools you need to integrate SMS functionality into your applications seamlessly.

1 – Create Account on Twilio :

Twilio is paid Solution, but you can start with trial account :

After creating your trial account, you’ll get this information :

  • Account SID
  • Auth Token
  • Phone Number

Now, we will complete PowerShell Script with these 3 informations.

2 – PowerShell Script :

Replice 5 first variables with your own values ($accountSid, $authToken, $from, $to, $body) :

# Twilio login information to change
$accountSid = "AC1c778396c23eab91cb921324156465465"
$authToken = "6142fad94654sd654f6sda34198b2cb4d"
$from = "+12189934936"       # Twilio Number
$to = "+15141112233"         # destination Number
$body = "Hi Aymen , This is a Message sent via PowerShell !"

# Create query object
$uri = "https://api.twilio.com/2010-04-01/Accounts/$accountSid/Messages.json"
$bodyData = @{
    To = $to
    From = $from
    Body = $body
}

# Send via Invoke-RestMethod
$response = Invoke-RestMethod -Uri $uri -Method Post -Body $bodyData -Credential (New-Object System.Management.Automation.PSCredential($accountSid, (ConvertTo-SecureString $authToken -AsPlainText -Force)))

# Show answer
$response.sid 

Result :

  • As you can see, here is my text message :

Conclusion

By following the steps outlined in this guide, you will be able to harness the power of PowerShell and Twilio to send SMS messages with ease. This capability can enhance your communication strategies, streamline workflows, and improve overall efficiency. I hope you find this guide helpful and that it empowers you to explore new possibilities in your technical endeavors. Thank you for reading, and happy coding !

Thanks

Aymen EL JAZIRI (Microsoft MVP)
Aymen EL JAZIRI (Microsoft MVP)

Hi, I’m Aymen El Jaziri , a passionate System Administrator and Microsoft MVP, with years of hands-on experience in managing and securing modern IT infrastructures.
This blog is where I share technical guides, automation scripts, product reviews, and real-world solutions that help IT professionals simplify their day-to-day work and stay ahead in a fast-evolving cloud ecosystem.
Whether you’re here to troubleshoot an issue, improve your automation game, or learn new best practices , welcome in my blog !
Let’s build a stronger, smarter IT community together.
Feel free to connect with me on LinkedIn for more content, discussions, or collaboration opportunities.

Thanks

Aymen

Articles: 154