@@ -5,149 +5,51 @@ function Invoke-WPFUpdatesdefault {
55 Resets Windows Update settings to default
66
77 #>
8+ $ErrorActionPreference = ' SilentlyContinue'
89
9- Write-Host " Restoring Windows Update registry settings..." - ForegroundColor Yellow
10+ Write-Host " Removing Windows Update policy settings..." - ForegroundColor Green
1011
11- If (! (Test-Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" )) {
12- New-Item - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" - Force | Out-Null
13- }
14- Set-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" - Name " NoAutoUpdate" - Type DWord - Value 0
15- Set-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" - Name " AUOptions" - Type DWord - Value 3
16- If (! (Test-Path " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" )) {
17- New-Item - Path " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" - Force | Out-Null
18- }
19- Set-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" - Name " DODownloadMode" - Type DWord - Value 1
20-
21- # Reset WaaSMedicSvc registry settings to defaults
22- Write-Host " Restoring WaaSMedicSvc settings..." - ForegroundColor Yellow
23- Set-ItemProperty - Path " HKLM:\SYSTEM\CurrentControlSet\Services\WaaSMedicSvc" - Name " Start" - Type DWord - Value 3 - ErrorAction SilentlyContinue
24- Remove-ItemProperty - Path " HKLM:\SYSTEM\CurrentControlSet\Services\WaaSMedicSvc" - Name " FailureActions" - ErrorAction SilentlyContinue
25-
26- # Restore update services to their default state
27- Write-Host " Restoring update services..." - ForegroundColor Yellow
28-
29- $services = @ (
30- @ {Name = " BITS" ; StartupType = " Manual" },
31- @ {Name = " wuauserv" ; StartupType = " Manual" },
32- @ {Name = " UsoSvc" ; StartupType = " Automatic" },
33- @ {Name = " uhssvc" ; StartupType = " Disabled" },
34- @ {Name = " WaaSMedicSvc" ; StartupType = " Manual" }
35- )
36-
37- foreach ($service in $services ) {
38- try {
39- Write-Host " Restoring $ ( $service.Name ) to $ ( $service.StartupType ) ..."
40- $serviceObj = Get-Service - Name $service.Name - ErrorAction SilentlyContinue
41- if ($serviceObj ) {
42- Set-Service - Name $service.Name - StartupType $service.StartupType - ErrorAction SilentlyContinue
43-
44- # Reset failure actions to default using sc command
45- Start-Process - FilePath " sc.exe" - ArgumentList " failure `" $ ( $service.Name ) `" reset= 86400 actions= restart/60000/restart/60000/restart/60000" - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
12+ Remove-Item - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" - Recurse - Force
13+ Remove-Item - Path " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization" - Recurse - Force
14+ Remove-Item - Path " HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" - Recurse - Force
15+ Remove-Item - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\Device Metadata" - Recurse - Force
16+ Remove-Item - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\DriverSearching" - Recurse - Force
17+ Remove-Item - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" - Recurse - Force
4618
47- # Start the service if it should be running
48- if ($service.StartupType -eq " Automatic" ) {
49- Start-Service - Name $service.Name - ErrorAction SilentlyContinue
50- }
51- }
52- }
53- catch {
54- Write-Host " Warning: Could not restore service $ ( $service.Name ) - $ ( $_.Exception.Message ) " - ForegroundColor Yellow
55- }
56- }
57-
58- # Restore renamed DLLs if they exist
59- Write-Host " Restoring renamed update service DLLs..." - ForegroundColor Yellow
19+ Write-Host " Reenabling Windows Update Services..." - ForegroundColor Green
6020
61- $dlls = @ (" WaaSMedicSvc" , " wuaueng" )
21+ Write-Host " Restored BITS to Manual"
22+ Set-Service - Name BITS - StartupType Manual
6223
63- foreach ($dll in $dlls ) {
64- $dllPath = " C:\Windows\System32\$dll .dll"
65- $backupPath = " C:\Windows\System32\${dll} _BAK.dll"
24+ Write-Host " Restored wuauserv to Manual"
25+ Set-Service - Name wuauserv - StartupType Manual
6626
67- if ((Test-Path $backupPath ) -and ! (Test-Path $dllPath )) {
68- try {
69- # Take ownership of backup file
70- Start-Process - FilePath " takeown.exe" - ArgumentList " /f `" $backupPath `" " - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
27+ Write-Host " Restored UsoSvc to Automatic"
28+ Set-Service - Name UsoSvc - StartupType Automatic
7129
72- # Grant full control to everyone
73- Start-Process - FilePath " icacls.exe " - ArgumentList " `" $backupPath `" /grant *S-1-1-0:F " - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
30+ Write-Host " Restored WaaSMedicSvc to Manual "
31+ Set-Service - Name WaaSMedicSvc - StartupType Manual
7432
75- # Rename back to original
76- Rename-Item - Path $backupPath - NewName " $dll .dll" - ErrorAction SilentlyContinue
77- Write-Host " Restored ${dll} _BAK.dll to $dll .dll"
78-
79- # Restore ownership to TrustedInstaller
80- Start-Process - FilePath " icacls.exe" - ArgumentList " `" $dllPath `" /setowner `" NT SERVICE\TrustedInstaller`" " - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
81- Start-Process - FilePath " icacls.exe" - ArgumentList " `" $dllPath `" /remove *S-1-1-0" - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
82- }
83- catch {
84- Write-Host " Warning: Could not restore $dll .dll - $ ( $_.Exception.Message ) " - ForegroundColor Yellow
85- }
86- }
87- }
33+ Write-Host " Enabling update related scheduled tasks..." - ForegroundColor Green
8834
89- # Enable update related scheduled tasks
90- Write-Host " Enabling update related scheduled tasks..." - ForegroundColor Yellow
91-
92- $taskPaths = @ (
93- ' \Microsoft\Windows\InstallService\*'
94- ' \Microsoft\Windows\UpdateOrchestrator\*'
95- ' \Microsoft\Windows\UpdateAssistant\*'
96- ' \Microsoft\Windows\WaaSMedic\*'
97- ' \Microsoft\Windows\WindowsUpdate\*'
35+ $Tasks =
36+ ' \Microsoft\Windows\InstallService\*' ,
37+ ' \Microsoft\Windows\UpdateOrchestrator\*' ,
38+ ' \Microsoft\Windows\UpdateAssistant\*' ,
39+ ' \Microsoft\Windows\WaaSMedic\*' ,
40+ ' \Microsoft\Windows\WindowsUpdate\*' ,
9841 ' \Microsoft\WindowsUpdate\*'
99- )
10042
101- foreach ($taskPath in $taskPaths ) {
102- try {
103- $tasks = Get-ScheduledTask - TaskPath $taskPath - ErrorAction SilentlyContinue
104- foreach ($task in $tasks ) {
105- Enable-ScheduledTask - TaskName $task.TaskName - TaskPath $task.TaskPath - ErrorAction SilentlyContinue
106- Write-Host " Enabled task: $ ( $task.TaskName ) "
107- }
108- }
109- catch {
110- Write-Host " Warning: Could not enable tasks in path $taskPath - $ ( $_.Exception.Message ) " - ForegroundColor Yellow
111- }
43+ foreach ($Task in $Tasks ) {
44+ Get-ScheduledTask - TaskPath $Task | Enable-ScheduledTask - ErrorAction SilentlyContinue
11245 }
11346
114- Write-Host " Enabling driver offering through Windows Update..."
115- Remove-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\Device Metadata" - Name " PreventDeviceMetadataFromNetwork" - ErrorAction SilentlyContinue
116- Remove-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\DriverSearching" - Name " DontPromptForWindowsUpdate" - ErrorAction SilentlyContinue
117- Remove-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\DriverSearching" - Name " DontSearchWindowsUpdate" - ErrorAction SilentlyContinue
118- Remove-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\DriverSearching" - Name " DriverUpdateWizardWuSearchEnabled" - ErrorAction SilentlyContinue
119- Remove-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" - Name " ExcludeWUDriversInQualityUpdate" - ErrorAction SilentlyContinue
120- Write-Host " Enabling Windows Update automatic restart..."
121- Remove-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" - Name " NoAutoRebootWithLoggedOnUsers" - ErrorAction SilentlyContinue
122- Remove-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" - Name " AUPowerManagement" - ErrorAction SilentlyContinue
123- Write-Host " Enabled driver offering through Windows Update"
124- Remove-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" - Name " BranchReadinessLevel" - ErrorAction SilentlyContinue
125- Remove-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" - Name " DeferFeatureUpdatesPeriodInDays" - ErrorAction SilentlyContinue
126- Remove-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" - Name " DeferQualityUpdatesPeriodInDays" - ErrorAction SilentlyContinue
127-
128- Write-Host " ==================================================="
129- Write-Host " --- Windows Update Settings Reset to Default ---"
130- Write-Host " ==================================================="
131-
132- Start-Process - FilePath " secedit" - ArgumentList " /configure /cfg $env: windir \inf\defltbase.inf /db defltbase.sdb /verbose" - Wait
133- Start-Process - FilePath " cmd.exe" - ArgumentList " /c RD /S /Q $env: WinDir \System32\GroupPolicyUsers" - Wait
134- Start-Process - FilePath " cmd.exe" - ArgumentList " /c RD /S /Q $env: WinDir \System32\GroupPolicy" - Wait
135- Start-Process - FilePath " gpupdate" - ArgumentList " /force" - Wait
136- Remove-Item - Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies" - Recurse - Force - ErrorAction SilentlyContinue
137- Remove-Item - Path " HKCU:\Software\Microsoft\WindowsSelfHost" - Recurse - Force - ErrorAction SilentlyContinue
138- Remove-Item - Path " HKCU:\Software\Policies" - Recurse - Force - ErrorAction SilentlyContinue
139- Remove-Item - Path " HKLM:\Software\Microsoft\Policies" - Recurse - Force - ErrorAction SilentlyContinue
140- Remove-Item - Path " HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies" - Recurse - Force - ErrorAction SilentlyContinue
141- Remove-Item - Path " HKLM:\Software\Microsoft\Windows\CurrentVersion\WindowsStore\WindowsUpdate" - Recurse - Force - ErrorAction SilentlyContinue
142- Remove-Item - Path " HKLM:\Software\Microsoft\WindowsSelfHost" - Recurse - Force - ErrorAction SilentlyContinue
143- Remove-Item - Path " HKLM:\Software\Policies" - Recurse - Force - ErrorAction SilentlyContinue
144- Remove-Item - Path " HKLM:\Software\WOW6432Node\Microsoft\Policies" - Recurse - Force - ErrorAction SilentlyContinue
145- Remove-Item - Path " HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Policies" - Recurse - Force - ErrorAction SilentlyContinue
146- Remove-Item - Path " HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\WindowsStore\WindowsUpdate" - Recurse - Force - ErrorAction SilentlyContinue
47+ Write-Host " Windows Local Policies Reset to Default"
48+ secedit / configure / cfg " $Env: SystemRoot \inf\defltbase.inf" / db defltbase.sdb
14749
148- Write-Host " ==================================================="
149- Write-Host " --- Windows Local Policies Reset to Default ---"
150- Write-Host " ==================================================="
50+ Write-Host " ===================================================" - ForegroundColor Green
51+ Write-Host " --- Windows Update Settings Reset to Default ---" - ForegroundColor Green
52+ Write-Host " ===================================================" - ForegroundColor Green
15153
152- Write-Host " Note: A system restart may be required for all changes to take full effect." - ForegroundColor Yellow
54+ Write-Host " Note: You must restart your system in order for all changes to take effect." - ForegroundColor Yellow
15355}
0 commit comments