79766182

Date: 2025-09-16 11:42:57
Score: 1.5
Natty:
Report link

How to automate windows update using powershell and batch script?

  1. Create MSUpdates.log file in D: drive

  2. Create installpatchexecute.cmd in D: drive with this content:

    pushd D:

    powershell.exe .\installpatch.ps1

    if %errorlevel% neq 0 goto error

    popd

    goto end

    :error

    echo "An error occurred" >> D:\MSUpdates.log

    exit /b 1

    :end

    exit /b 0

  3. Create installpatch.ps1 file in D: drive with this content:

    netsh winhttp set proxy "xxxxxx:80" #(proxy if any)

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

    Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot | Out-File "D:\MSUpdates.log" -Force

  4. Create Schedule task to run on every monday at 6pm and relax :)

    pushd c:\windows\system32

    SCHTASKS /Create /S localhost /RU SYSTEM /SC WEEKLY /D MON /ST 18:00 /TN "InstallWindowsPatch" /TR "D:\installpatchexecute.cmd"

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): How to
  • Low reputation (0.5):
Posted by: Bhaskar Jagadeesha