Using powershell to update Windows servers


I am trying to create a powershell script to install all approved windows updates from our WSUS server.

However, when manually checking for updates on said server, if on retry, the script does not force retry of the updates. This is causing a problem. How can I force a “retry” when server calls for it?

Any suggestions on how to force an update when server says Retry update?

Below is my code:

$finished = 0

$n19server = Get-ADComputer -Filter {name -like ‘nw*’}

function Start-Sleep($seconds) {
$doneDT = (Get-Date).AddSeconds($seconds)
while($doneDT -gt (Get-Date)) {
$secondsLeft = $doneDT.Subtract((Get-Date)).TotalSeconds
$percent = ($seconds - $secondsLeft) / $seconds * 100
Write-Progress -Activity “Sleeping” -Status “Sleeping…” -SecondsRemaining $secondsLeft -PercentComplete $percent
Write-Progress -Activity “Sleeping” -Status “Sleeping…” -SecondsRemaining 0 -Completed

while ($finished -le 15) {

foreach ($servert in $n19server) {

   [string]$serverName = $
   Restart-Computer -ComputerName $serverName -Force


write-host “sleeping for 10 minutes”
$time = get-date -Format HH:mm:ss
write-host $time

foreach ($server in $n19server) {

   [string]$serverName = $
    Invoke-Command -ComputerName $serverName -ScriptBlock {
    Get-WindowsUpdate -verbose
    Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -Install -AutoReboot


write-host “sleeping for 30 minutes”
$time = get-date -Format HH:mm:ss
write-host $time


Hello and welcome to forums!

The module which you’re using is:
PowerShell Gallery | PSWindowsUpdate

From what I see the module does not provide a function for your issue, although you might find some code here:
PowershellModules/PSWindowsUpdate at master · dwj7738/PowershellModules (

If that’s not useful there is one possible solution but it will require some work:

When you run Get-WindowsUpdateLog -LogPath "path\to\log_file" it will generate a log in said location.

You’ll need to parse this log according to date and search for *FAILED* and similar depending on problem, then if there is fail you can retry command.

By “retry” you mean retry failed updates right?
btw. please edit your post to fix code formatting.