I have this Windows server installed which hosts a couple of websites, and is really not doing much.
Every now and then I need to log in for some server operation, only to find the typical Windows Updates Pending notification. Every time this happens I think to myself, hey, I’d like to get some notification that there are updates available, without having to log in.
So I finally dug around the internets – well, as it turned out, the info was all on StackOverflow:
- .Net Windows Update Querying
- Best way of detecting if Windows has Windows Updates ready to download/install?
- Output a PowerShell object into a string
The result is a tiny PowerShell script called update-mailer.ps1, which queries the Windows Update Service and sends an email accordingly, and can be found on my GitHub PowerShell repository.
To run this script as a Scheduled Task, create a .cmd batch file containing the command
powershell.exe -ExecutionPolicy Bypass -File path\to\update-mailer.ps1
to bypass PowerShell’s restricted execution policy, and call the script from the task.