How can we help?

Send and receive using PowerShell


You can use PowerShell to send and receive SMS messages with the SMS Server.

All that is required is to use the SMS Server API to create a new message in the SMS Server database. The SMS Server service will pick it up and send it automatically on the scheduled time.

For example, to send an SMS message you can use this script:

# Create global objects
$objMessageDB = new-object -comobject AxMmServer.MessageDB
$objConstants = new-object -comobject AxMmServer.Constants

write-host "API Module: " $objMessageDB.Module
write-host "API Version: " $objMessageDB.Build

# Create a new message object
$objMessage = $objMessageDB.Create("SMS")

$objMessage.DirectionID  = $objConstants.MESSAGEDIRECTION_OUT
$objMessage.ChannelID    = ""  # First available SMS channel
$objMessage.ScheduledTime = Get-Date # To indicate immediate schedule. 
# To schedule 1 day and 2 hours in advance, specify ((Get-Date).AddDays(1)).AddHours(2)
# To schedule on specific date/time, specify "12/25/2005 07:30"

$objMessage.ToAddress    = "31623123456"
$objMessage.Body         = "This is an Auron test message"

# Save the new values that were just assigned
$objMessageDB.Save($objMessage)
write-host "Save, result: " $objMessageDB.LastError " (" `
  $objMessageDB.GetErrorDescription($objMessageDB.LastError) ")"

write-host "Ready."

To list the 10 most recently received messages you can run this script:

# Create global objects
$objMessageDB = new-object -comobject AxMmServer.MessageDB

write-host "API Module: " $objMessageDB.Module
write-host "API Version: " $objMessageDB.Build

# Find and iterate over all messages
$objMessage = $objMessageDB.FindFirstMessage("SMS", "", "ID DESC", 10) 
While ($objMessageDB.LastError -eq 0)
{
  write-host "Messsage #" $objMessage.ID
  write-host "  StatusID: " $objMessage.StatusID " (" `
    $objMessageDB.GetStatusDescription( $objMessage.StatusID ) ")"
  write-host "  ChannelID: " $objMessage.ChannelID
  write-host "  Body: " $objMessage.Body 

  $objMessage = $objMessageDB.FindNextMessage()
}

write-host "Ready."