Windows Updates
Code Properties
- Language: PowerShell
- Modules:
PSWindowsUpdate- Requires: Administrator privileges
Overview
PowerShell script that uses the PSWindowsUpdate module to install all available Windows updates.
Code
#Requires -RunAsAdministrator
# transcript logging
$TranscriptFile = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-WindowsUpdate.log"
$TranscriptPath = Join-Path "$Env:TEMP\WindowsUpdate" $TranscriptFile
Start-Transcript -Path $TranscriptPath -ErrorAction Ignore | Out-Null
# execution policy
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
# install PSWindowsUpdate if needed
if (!(Get-Module -ListAvailable -Name PSWindowsUpdate)) {
Write-Verbose "Installing Module: PSWindowsUpdate..."
Install-Module -Name PSWindowsUpdate -Scope CurrentUser -Force
}
Import-Module PSWindowsUpdate
# install updates
Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -IgnoreReboot -ForceInstall
# restart
Write-Host "Restarting Machine in 20 seconds..."
Start-Sleep -Seconds 20
Restart-Computer -ForceUsage
# run as administrator
.\Install-WindowsUpdates.ps1
# or run commands individually
Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -IgnoreReboot
# check for updates without installing
Get-WindowsUpdate
# list update history
Get-WUHistoryAppendix
Note created on 2024-05-03 and last modified on 2024-12-31.
See Also
Backlinks
(c) No Clocks, LLC | 2024