Powershell script to automate Windows Updates using PSWindowsUpdate

PSWindowsUpdate is a module that automates windows updates using PowerShell. I work with a lot of desperate environments that aren’t connectedand not all machines are on a domain. The ones that are use different domains that are not trusted. That means WSUS isn’t an option. There are some third party options that could work like Shavlik, but I’m cheap and there aren’t enough servers to warrant the cost.

Using PSWindowsUpdate is great, but what’s the point in using it if I have to first manually install it on each server? I’m supposed to be “DevOps” after all and they automate or die. Something like that.

First, it downloads PSWindowsUpdate to the user’s downloads folder.
Then unzips it into the modules folder.
Then imports and runs the command to install all and reboot. Warning, this will install ALL updates and reboot. You can edit it to your liking, hide updates, and choose not to reboot. Just check the documentation here. Great guide here as well.

Also, after you have ran this once the module is installed and next maintenance night you can simply run Get-WUInstall.

Invoke-WebRequest -Uri "https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc/file/41459/43/PSWindowsUpdate.zip" -OutFile "$env:USERPROFILE\Downloads\PSWindowsUpdate.zip"
$shell = new-object -com shell.application
$zip = $shell.NameSpace("$env:USERPROFILE\Downloads\PSWindowsUpdate.zip")
foreach($item in $zip.items())
{
$shell.Namespace("C:\Windows\System32\WindowsPowerShell\v1.0\Modules\").copyhere($item)
}
Import-Module PSWindowsUpdate
Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d -Confirm:$false
Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot

Leave a Comment

Your email address will not be published.