Skip to main content

Repair Windows Update

Summary

This script attempts to repair and reset Windows update settings using the ProVal script: Repair-WindowsUpdate
The goal of this script is to fix potential patching issues for Windows devices.

Sample Run

Select any computer where you want to run the script. Then go to Play Button > Run Automation > Script
SampleRun1

Search the script name and click on it:
SampleRun

Select the parameters as per your requirement and then click on Run:
SampleRun

Click on Yes to run the script SampleRun

Dependencies

Repair-WindowsUpdate

Parameters

NameExampleAccepted ValuesRequiredDefaultTypeDescription
SfcScan--FalseFalseCheckboxToggles an optional SFC scan as a repair option for Windows updates
DISMRepair--FalseFalseCheckboxToggles an optional DISM repair
Reboot--FalseFalseCheckboxIf enabled, the script will forcefully restart the computer after completing the repair operations.

Automation Setup/Import

Step 1

Navigate to Administration > Library > Automation
Step1

Step 2

Locate the Add button on the right-hand side of the screen, click on it and click the New Script button.
Step2

The scripting window will open.
ScriptingScreen

Name: Repair Windows Update
Description: This is used to reset Windows update settings. It is not necessary that running the script will resolve any issue with the Windows updates. It will simply attempt to reset Windows update settings.
Categories: ProVal
Language: PowerShell
Operating System: Windows
Architecture: All
Run As: System

ScriptLogic

#region parameters
$SfcScan = $env:SfcScan
$DISMRepair = $env:DISMRepair

$Parameters = @{}

if ( $SfcScan -match '1|Yes|True' ) {
$Parameters.Add('SfcScan', $true)
}
if ( $DISMRepair -match '1|Yes|True' ) {
$Parameters.Add('DISMRepair', $true)
}
#endregion
#region Setup - Variables
$ProjectName = 'Repair-WindowsUpdate'
[Net.ServicePointManager]::SecurityProtocol = [enum]::ToObject([Net.SecurityProtocolType], 3072)
$BaseURL = 'https://file.provaltech.com/repo'
$PS1URL = "$BaseURL/script/$ProjectName.ps1"
$WorkingDirectory = "C:\ProgramData\_automation\script\$ProjectName"
$PS1Path = "$WorkingDirectory\$ProjectName.ps1"
$WorkingPath = $WorkingDirectory
$LogPath = "$WorkingDirectory\$ProjectName-log.txt"
$ErrorLogPath = "$WorkingDirectory\$ProjectName-Error.txt"
#endregion
#region Setup - Folder Structure
New-Item -Path $WorkingDirectory -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
$response = Invoke-WebRequest -Uri $PS1URL -UseBasicParsing
if (($response.StatusCode -ne 200) -and (!(Test-Path -Path $PS1Path))) {
throw "No pre-downloaded script exists and the script '$PS1URL' failed to download. Exiting."
} elseif ($response.StatusCode -eq 200) {
Remove-Item -Path $PS1Path -ErrorAction SilentlyContinue
[System.IO.File]::WriteAllLines($PS1Path, $response.Content)
}
if (!(Test-Path -Path $PS1Path)) {
throw 'An error occurred and the script was unable to be downloaded. Exiting.'
}
#endregion
#region Execution
if ($Parameters) {
& $PS1Path @Parameters
} else {
& $PS1Path
}
#endregion
#region log verification
if ( !(Test-Path $LogPath) ) {
throw 'PowerShell Failure. A Security application seems to have restricted the execution of the PowerShell Script.'
}
if ( Test-Path $ErrorLogPath ) {
$ErrorContent = ( Get-Content -Path $ErrorLogPath )
throw $ErrorContent
}
Get-Content -Path $LogPath
#endregion

ScriptLogic

Script Variables

Click the Add button next to Script Variables.
AddVariableButton

Select the Checkbox option.
Checkbox

The Add Checkbox Variable window will open.
Checbox

In the box, fill in the following details and select Add to create the script variable.

Name: SfcScan
Description: Toggles an optional SFC scan as a repair option for Windows updates.
Set Default Value: <Leave it Unchecked>
Checbox

Add another Script variable and Select the Checkbox option. Add Checkbox Variable window will open. In the box, fill in the following details and select Add to create the script variable.

Name: DISMRepair
Description: Toggles an optional DISM repair
Set Default Value: <Leave it Unchecked>
Checbox

Add another Script variable and Select the Checkbox option. Add Checkbox Variable window will open. In the box, fill in the following details and select Add to create the script variable.

Name: Reboot
Description: If enabled, the script will forcefully restart the computer after completing the repair operations.
Set Default Value: <Leave it Unchecked>
Checbox

Saving the Automation

Click the Save button in the top-right corner of the screen to save your automation.
SaveButton

If you are prompted to enter your MFA code, provide the code and press the Continue button to finalize the process.
MFA

Completed Automation

CompleteTask

Output

  • Activity Details