Bart Simons

Bart Simons

Thoughts, stories and ideas.

Bart Simons



Send SMS messages with PowerShell

Bart SimonsBart Simons


Programmatically sending SMS messages is easier than ever before. Companies like Nexmo and Twilio have been providing businesses with communication APIs that are so easy to implement in your current software that even the lowest skilled developers can work with it. The big disadvantage of all these services is that each provider has their own API specification.

Since I do a lot of my automation scripting with PowerShell, I decided to write a simple and easy-to-use PowerShell module to send SMS with one command. You - the developer - only have to specify the provider, recipient, sender and message. It can't get any easier!

Source code on GitHub

You can find the source code on GitHub:

Installation guide

Install PowerShell-SMS with this script that you have to copy-paste into your PowerShell window:

If ([Environment]::OSVersion.Platform -eq "Unix") {
    $ModulePath = [Environment]::GetEnvironmentVariable("PSModulePath").split(":")[0]
    If (Test-Path "$ModulePath/"){Remove-Item "$ModulePath/"}
    If (Test-Path "$ModulePath/PowerShell-SMS"){Remove-Item "$ModulePath/PowerShell-SMS" -Confirm:$false -Recurse -Force}
    Invoke-WebRequest -OutFile "$ModulePath/"
    Expand-Archive "$ModulePath/" -DestinationPath "$ModulePath"
    Remove-Item "$ModulePath/"
    Get-ChildItem "$ModulePath" | where { $_.Name -like "bmsimons-PowerShell-SMS*" } | % { Move-Item -Path ("$ModulePath/"+$_.Name) -Destination "$ModulePath/PowerShell-SMS" }
} Else {
    $ModulePath = [Environment]::GetEnvironmentVariable("PSModulePath").split(";")[0]
    If (Test-Path "$ModulePath\"){Remove-Item "$ModulePath\"}
    If (Test-Path "$ModulePath\PowerShell-SMS"){Remove-Item "$ModulePath\PowerShell-SMS" -Confirm:$false -Recurse -Force}
    Invoke-WebRequest -OutFile "$ModulePath\"
    Expand-Archive "$ModulePath\" -DestinationPath "$ModulePath"
    Remove-Item "$ModulePath/"
    Get-ChildItem "$ModulePath" | where { $_.Name -like "bmsimons-PowerShell-SMS*" } | % { Move-Item -Path ("$ModulePath\"+$_.Name) -Destination "$ModulePath\PowerShell-SMS" }

If you get an error, please use the open-source PowerShell version and run as admin if your modules folder is inaccessible by non-admins.

Cool, now you are ready to go!

Please note that documentation of this module is available on my GitHub repository. I am demonstration the use of Nexmo as a SMS API provider in this post so in case you want to learn more about other providers and their configuration parameters: check out my GitHub repository for a detailed guide on other SMS API providers.

Let's get started by configuring everything:

# Import the PowerShell-SMS module
Import-Module PowerShell-SMS

# Set the API key and API secret for Nexmo (this will be used for authentication)

# Send an SMS message to the recipient
Send-SMS -Provider Nexmo -From SENDERGOESHERE -To RECIPIENTGOESHERE -Message "Hello from PowerShell!"

Nexmo Send SMS

The recipient should receive the SMS message in no time:

Nexmo Receive SMS

Bart Simons

Bart Simons

View Comments