Call us: +45 50 322 322

Sample code – HTTP(s) – PowerShell

You can tell our SMS server, that you want to send a text message by making a HTTP request to our SMS script.

The following Sample code shows, how to make an integration in PowerShell with HTTPs:

$ToDoDirectory = 'C:\Temp\Inbox'
$FinishedDirectory = 'C:\Temp\SentBox'
$urlTemplate = 'https://api.suresms.com/Script/SendSMS.aspx?login={0}&password={1}&to={2}&Text={3}'
$smsGateLogin = 'xxxx'
$smsGatePassword = 'yyyyy'

 $filesToDo = @([ System.IO.Directory]::EnumerateFiles($ToDoDirectory,'*.sms', [ System.IO.SearchOption]::TopDirectoryOnly))
foreach ($fileToDo in $filesToDo)
{

$smsNumber = get-content -path $fileToDo |Select-Object -First 1
$smsText = get-content -path $fileToDo |Select-Object -Last 1

$uri = [String]::Format($urlTemplate, $smsGateLogin, $smsGatePassword, $smsNumber, $smsText)
$requestResult = Invoke-WebRequest -Method get -Uri $uri


$destSmsFile = [System.IO.Path]::Combine($FinishedDirectory, [ System.IO.Path]::GetFileName($fileToDo))
[ System.IO.File]::Move($fileToDo, $destSmsFile)
}

It is nessasary to change the parametres, so that they do match the username and Password, you recieved when opening your SureSMS account!

In order to run the PowerScript you can run the following command

C:\>powershell.exe -executionpolicy bypass -file sendsms.ps1

 

Should you have any questions, you are allways welcome to send an E-mail to support@suresms.com. We are looking forward to helping you.