-
Notifications
You must be signed in to change notification settings - Fork 0
/
windowsupdatechecker.ps1
34 lines (27 loc) · 975 Bytes
/
windowsupdatechecker.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
Import-Module PSWindowsUpdate
# Get all updates
$AllUpdates = Get-WindowsUpdate
# Filter for updates with status '-D-----'
$PendingUpdates = $AllUpdates | Where-Object { $_.Status -eq '-D-----' }
if ($PendingUpdates) {
# Updates are found with status '-D-----'
$BodyMessage = "Windows Update: There are updates pending installation."
# Prepare the request
$Request = @{
Method = "POST"
URI = "https://ntfy.sh/youShouldSelfHostOrBuyPremium"
Headers = @{
## See Ntfy - Authentication for more info (https://docs.ntfy.sh/publish/#authentication)
# Authorization = "Bearer <tokenHere>" ##Powershell 5 and earlier example
}
Body = $BodyMessage
}
Invoke-RestMethod @Request
} else {
Write-Output "Windows Update: No updates available."
}
Exit
# Get the current PowerShell process
$CurrentProcess = Get-Process -Id $PID
# Stop the PowerShell process
$CurrentProcess | Stop-Process -Force