Send-SMSMessage (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1999"></script>download | new post
Function to send text messages (SMS) from Windows PowerShell using the Microsoft Outlook SMS Add-in.
For more information, see the following blog-post:
http://blog.powershell.no/2010/07/21/send-text-messages-sms-using-windows-powershell
- #requires -version 2
- function Send-SMSMessage {
- <#
- .SYNOPSIS
- Send a Text Message (SMS) using Microsoft Outlook
- .DESCRIPTION
- Sends a Text Message (SMS) using the supplied parameters.
- .PARAMETER To
- Telephone number to send the text message to.
- .PARAMETER Message
- The message to send.
- .EXAMPLE
- Send-SMSMessage -To 555-12345 -Message "This is a test message"
- .NOTES
- Requires Windows PowerShell v2 and Microsoft Office Outlook 2010.
- Not tested in Outlook 2003 or 2007, but it should work with the Microsoft Outlook SMS Add-in installed (download from Microsoft).
- AUTHOR: Jan Egil Ring
- BLOG: http://blog.powershell.no
- LASTEDIT: 21.07.2010
- #>
- [CmdletBinding()]
- param (
- [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
- $To,
- [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
- $Message
- )
- #Check if Outlook are running
- $OutlookState = Get-Process | Where-Object {$_.Name -eq "outlook"}
- #Check whether Outlook is installed
- if (-not (Test-Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE")) {
- Write-Warning "Outlook are not installed. The message was not sent."
- break
- }
- #Check wheter an Text Messaging (SMS) account are set up in Outlook
- $outlook = New-Object -ComObject outlook.application
- if (-not (($outlook.Session.Accounts | Where-Object {$_.AccountType -eq "5"} | Measure-Object).Count -gt 0)) {
- Write-Warning "Outlook are installed, but no accounts are configured for Text Messaging (SMS). The message was not sent."
- break
- }
- #Send message
- $NewMessage = $outlook.CreateItem("olMobileItemSMS")
- $NewMessage.To = $To
- $NewMessage.Body = $Message
- $NewMessage.Send($true)
- #Close outlook.exe if it was not running before executing this function
- if (-not $OutlookState) {
- $outlook.Quit()
- }
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository