PoshCode Logo PowerShell Code Repository

Make a phone call by Sunny Chakrabort 5 years ago (modification of post by Sunny Chakrabort view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/3369"></script>download | new post

Make a phone call from Powershell and pass TextToSpeech variables like ComputerName, DiskFreeSpace.
User will receive a phone call with >
Please check the server $this.
The percent Free Space on C Drive is $inDecimals.
Don’t forget to change $mycell variable with your own cell

Feel free to pass other variables, and let me know if you want me to edit the script to allow these variables to pass through to the call.

  1. <#
  2.  
  3. .NOTES
  4.     AUTHOR: Sunny Chakraborty(sunnyc7@gmail.com)
  5.         WEBSITE: http://tekout.wordpress.com
  6.     VERSION: 0.1
  7.         CREATED: 17th April, 2012
  8.         LASTEDIT: 17th April, 2012
  9.         Requires: PowerShell v2 or better
  10.  
  11. .CHANGELOG
  12. 4/17/2012 Try passing powershell objects to PROTO API and pass the variables to .JS file
  13.         Pass other system variables and check if text to speech can translate double or a double-to-char conversion is required.
  14. 4/18/2012 Changed get-diskusage to gwmi -class win32_logicaldisk
  15.  
  16. .SYNOPSIS
  17.     Make a phone call from Powershell.
  18.        
  19. .DESCRIPTION
  20.         The script demonstrates how you can collect state-data in powershell and pass it as an argument to a REST API call and alert a System Admin.
  21.         For this example, TROPO REST API's were used. (www.tropo.com)
  22.         The phone-number will receive a Call with the following text To speech
  23.                 Please check the server $this.
  24.                 The percent Free Space on C Drive is $inDecimals.
  25.  
  26.         This is a proof of concept. V 0.1
  27.         There are numerous areas of improvement.
  28.        
  29. .IMPORTANT
  30.         Please create a new account and setup your application in tropo. Its free for dev use. http://www.tropo.com
  31.         Copy and replace the TOKEN in your application with the TOKEN below to initiate a call.
  32.        
  33. .OTHER
  34.  
  35. JAVASCRIPT (Hosted on Tropo)
  36.  
  37. TropoTest.js
  38. call('+' + numToCall , {
  39.   timeout:30,
  40.   callerID:'19172688401',
  41.       onAnswer: function() {
  42.         say("Houston ! We have a problem ");
  43.         say("Please check the server" + sourceServer );
  44.         say("The percent Free Space on C Drive is" + freeCDisk );
  45.         say("Goodbye.");
  46.         log("Call logged Successfully");
  47.   },
  48.   onTimeout: function() {
  49.         log("Call timed out");
  50.   },
  51.   onCallFailure: function() {
  52.         log("Call could not be completed as dialed");
  53.   }
  54. });
  55.  
  56. #>
  57.  
  58. # Proto API section. Please replace protoToken with your own Application Token,
  59. # I am posting my API token here so that someone can download and run the script by editing just the cell # field.
  60. $baseUrl = "https://api.tropo.com/1.0/sessions?action=create&"
  61.  
  62. # Modify these variables.
  63. $protoToken = "10b0026696a79f448eb21d8dbc69d78acf12e2f1f62f291feecec8f2b8d1eac76da63d91dd317061a5a9eeb0"
  64. #US 10 Digit only for now. For Example 17327911234,19177911234  
  65. # Calls to Outside US are not allowed during the dev trials on Tropo.
  66. # You will receive a call from this number - 19172688401. That's the callerID
  67. $myCell = '11234567890'
  68.  
  69. # Functions
  70. #4.18.12 -- Previous versoin used Get-DiskUsage and was erroring out if the cmldet is not installed.
  71. #modified it to use GWMI
  72. Function get-FreeDiskPercentForC {
  73. $disk = gwmi -class "win32_LogicalDisk"
  74. $free = $disk[0].FreeSpace / $disk[0].Size
  75. $freeDiskCPercent = [System.Math]::Round($free, 2)
  76. $freeDiskCPercent
  77. }
  78.  
  79. # Get some more parameters here.
  80. $sourceServer =hostname
  81. $cDisk = get-FreeDiskPercentForC
  82.  
  83. # Concatenate and form the Proto API string. I am sure someone can figure out a better way to do this than just adding.
  84. $callThis = $baseUrl+ 'token=' + $protoToken + '&numToCall=' + $myCell + '&sourceServer=' + $sourceServer + '&freeCDisk=' + $cDisk
  85.  
  86. # Call the Proto API
  87. # I could have tested this with Invoke-RestMethod, but I didn't see the point. I am not receiving any data from the URL.
  88. $newClient = new-object System.Net.WebClient
  89. $newClient.DownloadString($callThis)

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.

Syntax highlighting:


Remember me