Worklet - Reset Windows Update - Now with intensity

This worklet is going to reset the components of Windows Update. Windows Update can sometimes pull down a patch that is corrupted and needs to be cleared out. Digging manually through all of the patches can be tedious and depending on the age of the machine very time intensive. Instead this worklet will rename your old patch folders to .bak and allow Windows to generate a new one within a couple minutes.
This is designed to be run manually so do not schedule this to be run on a regular basis. It should only be run against a machine that is repeatedly failing to install updates.

Eval

{
Exit 0
}
Else {
Exit 1
}

Rem

$services = 'BITS','wuauserv','appidsvc','cryptsvc'

#Stop BITS, WUAUSERV, APPIDSVC AND CRYPTSVC Services
Stop-Service -Name bits
Stop-Service -Name wuauserv
Stop-Service -Name appidsvc
Stop-Service -Name cryptsvc

Foreach ($service in $services)
{
#check the status of the service to make sure it's stopped
    $service_status = (Get-Service -name $service).Status
    
    #if service is running
    if ($service_status -eq 'Running')
    {
    
    #stop service again
    Stop-Service -Name $service
    Start-Sleep -seconds 5
    
    }   
        #check if service is running again
    if (((Get-Service -name $service).Status) -eq 'Stopped')
    {
    }
        Else 
        {
        Exit 1
    }
}

#Removing old backups of these folders. In case you have run this worklet more then once
Remove-Item $env:systemroot\SoftwareDistribution.bak -recurse -force
Remove-Item $env:systemroot\Catroot2.bak -recurse -force

#Rename SoftwareDistribution and catroot2 folder
Rename-Item $env:systemroot\SoftwareDistribution SoftwareDistribution.bak
Rename-Item $env:systemroot\System32\Catroot2 Catroot2.bak

#Starting services
Foreach ($service in $services)
{
    Start-Service -Name $service
    }
2 Likes