1

Why I want to do this:

When Windows Update ran without warning, hogged resources and rendered my computer nearly unusable for a long time,

I had used:

 net stop wuauserv
 wmic service where name="TrustedInstaller" call stopservice
 taskkill /f /im TiWorker.exe

And met serious consequence(update failed and kept being installed upon (re)boot and kept being rolled back), however it is important to keep my computer up to date for security.

What I want to achieve

Schedule a time to automatically scan, download and install updates and prevent unscheduled auto-update, only install updates while I am not using my computer, so that it will not slow down my PC.

What I had tried

cmd:

Reg Add HKLM\SYSTEM\CurrentControlSet\Services\TrustedInstaller /v Start /t REG_dword /d 3 /f
Reg Add HKLM\SYSTEM\CurrentControlSet\Services\UsoSvc /v Start /t REG_dword /d 3 /f
Reg Add HKLM\SYSTEM\CurrentControlSet\Services\WaaSMedicSvc /v Start /t REG_dword /d 3 /f
Reg Add HKLM\SYSTEM\CurrentControlSet\Services\wuauserv /v Start /t REG_dword /d 3 /f

I can confirm these settings won't achieve my intended result.

gpedit.msc "Local Computer Policy"->"Computer Configuration"->"Administrative Templates"->"Windows Components"->"Windows Update"->"Configure Automatic Updates"

I had configured it to this:

enter image description here

(At 00:00 every Sunday on fourth week of every month)

And the effect:

enter image description here

If not all updates are restricted to the schedule, then it means nothing;

I know I can pause Windows Update but I doing it manually would be tiresome, though pausing Windows Update is useful. I am able to use taskschd to create scheduled tasks for script files, I want to programmatically pause Windows Update and schedule automatic update.

Update:

I have managed these with the help of @TOOGAM, using info from this link:

https://erdentec.com/pausing-windows-10-updates-indefinitely/

What I achieved:

$PauseStart=(Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$PauseEnd=(Get-Date).AddMonths(1).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "PauseFeatureUpdatesEndTime" -Type "String" -Value $PauseEnd
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "PauseQualityUpdatesEndTime" -Type "String" -Value $PauseEnd
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "PauseUpdatesExpiryTime" -Type "String" -Value $PauseEnd
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "PauseFeatureUpdatesStartTime" -Type "String" -Value $PauseStart
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "PauseQualityUpdatesStartTime" -Type "String" -Value $PauseStart
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "AUOptions" -Type "DWord" -Value 2
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "NoAutoUpdate" -Type "DWord" -Value 1
Start-Service -Name "Wuauserv"

However I can't let it automatically install updates, I had run this:

Get-Command -Module *Update*

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Get-WindowsUpdateLog                               1.0.0.0    WindowsUpdate
Function        Get-WUAVersion                                     1.0.0.2    WindowsUpdateProvider
Function        Get-WUIsPendingReboot                              1.0.0.2    WindowsUpdateProvider
Function        Get-WULastInstallationDate                         1.0.0.2    WindowsUpdateProvider
Function        Get-WULastScanSuccessDate                          1.0.0.2    WindowsUpdateProvider
Function        Install-WUUpdates                                  1.0.0.2    WindowsUpdateProvider
Function        Start-WUScan                                       1.0.0.2    WindowsUpdateProvider

I had run this and encountered an error:

Start-WUScan
Invoke-CimMethod: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\WindowsUpdateProvider\MSFT_WUOperations.psm1:13
Line |
  13 |  …  $scanres = Invoke-CimMethod -Namespace root/Microsoft/Windows/Window …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Provider load failure

Start-WUScan: Scan hit error: .ReturnValue

Also I am unable to make PowerShell manage scheduled tasks located in \Microsoft\Windows\WindowsUpdate in taskschd(although I can use schtasks in cmd and I know I can use cmd commands in pwsh but I want to do this in pure PowerShell spirit...)

I am able to use taskschd and I can create a scheduled task to run .ps1 files(just put "C:\Program Files\PowerShell\7\pwsh.exe" into program/script and use -file path\to\ps1 as argument)

How can I solve the problems that are in my way?

Update:

I had installed the Module: PSWindowsUpdate

Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Install-Module -Name PSWindowsUpdate

Had run this and here is the result:

Get-WindowsUpdate

ComputerName Status     KB          Size Title
------------ ------     --          ---- -----
UTILCOM-466… -------    KB4577194  607MB SQL Server 2019 RTM Cumulative Update (CU) 8 KB4577194
UTILCOM-466… -D-----    KB4592438  103GB 2020-12 Cumulative Update for Windows 10 Version 20H2 for x64-based Systems (…

Notice the size of KB4592438... It's 103GB...

Have a look at this:

https://www.catalog.update.microsoft.com/Search.aspx?q=KB4592438

enter image description here

What on earth is wrong?

I had put together this:

if ("PSWindowsUpdate" -notin (Get-Module -ListAvailable).name) {Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted;Install-Module -Name PSWindowsUpdate}

I know I can use:

Get-WindowsUpdate
Install-WindowsUpdate

Theoretically it will work, but look at the size of KB4592438 shown by Get-WindowsUpdate...

Disclaimer:

I Know I can use this cmd one-liner to automatically scan, download and install Windows Update, but that isn't PowerShell and this is strictly against pure PowerShell spirit, I had explicitly stated that I intend to use "PowerShell Core 7" and "Task Scheduler" to achieve this and only using them, not cmd, which in my view isn't professional enough:

wuauclt /detectnow /updatenow
10
  • Personally, I just paused the updates until the year 9999 using a modification of information at erdentec.com/pausing-windows-10-updates-indefinitely
    – TOOGAM
    Commented Dec 30, 2020 at 10:54
  • @TOOGAM I had accessed the address you gave me, and that is exactly the information I was looking for, thanks, I can create a powershell script from it... Commented Dec 30, 2020 at 11:20
  • This PowerShell Module could also be interesting for you. powershellgallery.com/packages/PSWindowsUpdate/2.2.0.2
    – Balthazar
    Commented Dec 30, 2020 at 17:00
  • Please will someone migrate this question to stackoverflow? I think it's a specific programming thing. Commented Dec 31, 2020 at 13:41
  • What are you having a problem with here Alien, anything at all still? Also, for Windows 10 use usoclient /startinteractivescan. Is the issue really issues automating Windows 10 still or are you thinking something is earthly corrupt per the misjudged size of 103GB for the cumulative update? The key to triggering the Windows Updates when you want it to also set the Active Hours and use the correlated usoclient commands either invoked remotely or on the machine itself at the times you need it to run, etc. @XeнεiΞэnвϵς Commented Jan 16, 2021 at 20:03

0

You must log in to answer this question.