-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathntfy_send.ps1
More file actions
32 lines (28 loc) · 1 KB
/
ntfy_send.ps1
File metadata and controls
32 lines (28 loc) · 1 KB
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
$topic = "topic_name" # Use a secure, unguessable topic name
$username = "username"
$password = "password"
$messageBody = "Hello friend, this is just a test."
$messageTitle = "Security Alert"
$ntfyServer = "https://ntfy.sh"
# This is a secure way to handle credentials in PowerShell
$credential = New-Object System.Management.Automation.PSCredential($username, (ConvertTo-SecureString $password -AsPlainText -Force))
# Encode credentials for Basic Authentication
$authHeader = "Basic " + [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($username + ":" + $password))
# Define the request parameters
$requestParams = @{
Method = "POST"
URI = "$($ntfyServer)/$($topic)"
Body = $messageBody
Headers = @{
"Title" = $messageTitle
"Authorization" = $authHeader
}
}
# Send the notification
try {
Invoke-RestMethod @requestParams
Write-Host "Ntfy message sent successfully to topic '$topic'."
}
catch {
Write-Host "An error occurred: $($_.Exception.Message)"
}