-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserialSMS.ps1
70 lines (60 loc) · 1.35 KB
/
serialSMS.ps1
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
65
66
67
68
69
70
param(
[string]$number = '',
[string]$message = ''
)
# Enter PSScriptRoot
cd $PSScriptRoot
# Init
. "$PSScriptRoot\init.ps1"
# Import config
. "$PSScriptRoot\config.ps1"
# UTF
if ($UTF) {
. "$PSScriptRoot\ConvertTo-HexString.ps1"
$numberHEX = $($number | ConvertTo-HexString -Encoding BigEndianUnicode -Delimiter '')
$messageHEX = $($message | ConvertTo-HexString -Encoding BigEndianUnicode -Delimiter '')
}
# Select USB port
Get-Port
try {
$port.open()
$port.Write("AT+CMGF=1`r")
Start-Sleep 5
$port.ReadLine()
If ($UTF) {
$port.Write("AT+CSCS=`"UCS2`"`r")
$port.ReadLine()
Start-Sleep 1
$port.Write("AT+CSMP=17,168,0,8`r")
$port.ReadLine()
Start-Sleep 1
$port.Write("AT+CMGS=`"$numberHEX`"`r")
Start-Sleep 1
$port.Write("$messageHEX`r")
$port.ReadLine()
}
else {
$port.Write("AT+CMGS=`"$number`"`r")
Start-Sleep 1
$port.ReadLine()
$port.Write("$message`r")
$port.ReadLine()
}
$z = new-Object String(26, 1)
$port.Write("`r")
$port.Write($z)
Start-Sleep 1
$output = $port.ReadExisting()
ForEach ($line in $output) {
if ( $line.contains("ERR")) {
Throw "ERROR IN COMMAND: $line"
}
}
}
catch {
Add-Content -Path $ErrLogFile -Value $("SMS [" + (LogFormat) + "] " + "`n" + $_.Exception.Message)
$port.Close()
Throw "ERROR FOUND $line"
}
$port.Close()
Start-Sleep 1