forked from NARKOZ/hacker-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangover.psm1
64 lines (56 loc) · 2.05 KB
/
hangover.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<#
.SYNOPSIS
Simple script to SMS a supervisor informing them you will be working from home
on the day this script is used.
.DESCRIPTION
This script was converted using the ruby version of the hangover script. However, the ruby
version used environment variables to hold the user's account information. Due to issue #42
(https://github.com/NARKOZ/hacker-scripts/issues/42) I opted to hard code the strings at
this time until a decision is made by NARKOZ, the project owner, as the how the information
should be stored.
This script also uses Twilio to send the SMS messages. The from number MUST be a valid Twilio
phone number. The to number can be any outgoing number.
.OUTPUT
This script will output an error message to the PowerShell window if it fails
to send the message.
.NOTES
Author: Tyler Hughes
Twitter: @thughesIT
Blog: http://tylerhughes.info/
Changelog:
1.0 Initial Release
#>
Function Hangover
{
# Phone numbers (Must include country code and area code)
$from = '+XXXXXXXXXXX'
$to = '+XXXXXXXXXXX'
# Twilio API Information
$twilio_base_url = 'https://api.twilio.com/2010-04-01'
$twilio_account_sid = 'XXXXXXXXXXXXXXXXXXX'
$twilio_auth_token = 'XXXXXXXXXXXXXXXXXX'
$password = ConvertTo-SecureString -AsPlainText $twilio_auth_token -Force
$credentials = New-Object System.Management.Automation.PSCredential($twilio_account_sid, $password)
# Get the message to send
$excuses =
'Locked out',
'Pipes broke',
'Food poisoning',
'Not feeling well'
$excuse = $excuses | Get-Random
$message = "$excuse. Going to work from home today."
$body = @{
From = $from;
To = $to;
Body = $message;
}
# Send the message and log any errors
$uri = "$twilio_base_url/Accounts/" + $credentials.UserName + "/SMS/Messages"
try {
$response = Invoke-RestMethod -Method Post -Uri $uri -Body $body -Credential $credentials
}
catch {
$time = Get-Date -format u
Write-Host $time " - Failed to send message: " $message
}
}