PSWindowsUpdate
Install Windows Updates with the PSWindowsUpdate PowerShell module.
1# Set the PowerShell script execution policy to 'RemoteSigned' for the current process.
2# This allows locally-created scripts to run without requiring a digital signature, while scripts downloaded from the internet need to be signed by a trusted publisher.
3Set-ExecutionPolicy RemoteSigned -Scope Process -Force
4
5# Install the 'PSWindowsUpdate' module from the PowerShell Gallery.
6# -Force: Forces the command to run without asking for user confirmation.
7# -AllowClobber: Overwrites any existing cmdlets/functions with the same name.
8Install-Module -Name PSWindowsUpdate -Force -AllowClobber
9
10# Import the 'PSWindowsUpdate' module into the current PowerShell session to use its cmdlets.
11Import-Module PSWindowsUpdate
12
13# Retrieve and display a list of all available updates from Microsoft Update.
14# -MicrosoftUpdate: Checks for updates from Microsoft Update, not just Windows Update.
15Get-WindowsUpdate -MicrosoftUpdate
16
17# Download all available updates from Microsoft Update.
18# -AcceptAll: Automatically accepts all updates without prompting.
19# -Verbose: Shows detailed information about the download process.
20Download-WindowsUpdate -MicrosoftUpdate -AcceptAll -Verbose
21
22# Install all downloaded updates from Microsoft Update and automatically reboot if necessary.
23# -AcceptAll: Automatically accepts all updates without prompting.
24# -AutoReboot: Allows the system to automatically reboot if it's required after installing updates.
25Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot
26
27# Reset the PowerShell script execution policy to 'Restricted' for the current process.
28# This does not load configuration files or run scripts and is the default setting.
29Set-ExecutionPolicy Restricted -Scope Process -Force
WARNING
Don't forget to reset the PowerShell script execution policy back to 'Restricted' when you're done!