Information
Since its birth in November 2006
PowerShell has evolved to be the chosen tool of network administrators and advanced users alike. Originally a native Windows tool it has since August 2016 been an open source project, spreading its wings to other operating systems, too, starting with Linux.
According to
Wikipedia "
PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework".
PowerShell is often falsely thought to be a
Command Prompt replacement users reading wrong changes in late Windows 10 versions where PowerShell by default replaced Command Prompt in WIN + X menu; however, both have their own purpose and areas of expertise, both are and will remain integral parts of Windows 10.
PowerShell should not be feared, it can make administrative and maintenance tasks of a private user even with just a single PC a piece of cake with its logical
cmdlets (pronounced command let) and a relatively easy to learn scripting language.
The
cmdlet syntax is
VERB-NOUN, always answering the question
Do what? Add some parameters and you have a powerful command, like for instance
Hide-WUUpdate -KBArticleID "KB1234567"
as used later in this tutorial. Easy to understand: Hide (do not show / install) an update with knowledge base ID 1234567.
This tutorial will show how to take command of Windows Update using PowerShell. Tutorial will cover the basics, feel free to post in this thread if you have any questions.
Contents
Click links to jump to any part
Part One
Install PowerShell Windows Update Module
1.1) Download
PSWindowsUpdate.zip from
Microsoft TechNet:
Download
1.2) Right click the downloaded file, select
Extract all:
1.3) Extract ZIP archive to
C:\Windows\System32\WindowsPowerShell\v1.0\Modules
1.4) Select
Do this for all current items, click
Continue:
1.5) Open an
elevated (admin) PowerShell, change script execution policy from default
Restricted to
Unrestricted with following cmdlet:
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
Accept with
Y. When done, import
PSWindowsUpdate module with cmdlet:
Import-Module PSWindowsUpdate
Allow
PSWindowsUpdate by selecting
R (Run). This will be asked twice, separately for two PSWindowsUpdate scripts.
1.6) You can get a list of each available PSWindowsUpdate cmdlet with
Get-Command -Module PSWindowsUpdate
Part Two
Add support for additional Microsoft Products
2.1) In
Settings App > Update & Security > Windows Update > Advanced Options you can select to get updates to other Microsoft products when updating Windows. To add the same functionality to
PSWindowsUpdate run the following cmdlet:
Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d
Accept with
Y. Notice that the
ServiceID is constant string, exactly as shown above
This step is completely optional; if you do not Windows Update updating other products than Windows, simply skip it.
Part Three
Check, Install or Hide Windows Updates
3.1) To list all Windows and other Microsoft updates, enter the following cmdlet:
Get-WUInstall -MicrosoftUpdate -ListOnly
In this case there were only updates for Windows available.
3.2) To check available updates and feature upgrades for Windows only (not for additional Microsoft products) enter cmdlet:
Get-WUInstall -ListOnly
(Screenshot shows cmdlets for steps 3.2 to 3.6)
3.3) To hide an update you do not want to install you can filter with either full or partial title of an update, or its KB ID
3.4) Hide update
Microsoft Silverlight (KB4013867) using partial title
Microsoft:
Hide-WUUpdate -Title "Microsoft*" -Confirm:$False
This hides all updates where word Microsoft appears anywhere in update title. In my example case now the Silverlight update was the only one.
3.5) Hide the same update using KB ID instead of title:
Hide-WUUpdate -KBArticleID "KB4013867" -Confirm:$False
3.6) Same filters, title or KB ID can be used to unhide an update adding parameter
-HideStatus:$False
Hide-WUUpdate -Title "Microsoft*" -HideStatus:$False -Confirm:$False
-- OR --
Hide-WUUpdate -KBArticleID "KB4013867" -HideStatus:$False -Confirm:$False
3.7) To install all available, not hidden updates rejecting or accepting each installation manually, use this cmdlet:
Get-WUInstall
To also install additional Microsoft product updates:
Get-WUInstall -MicrosoftUpdate
3.8) You need to manually accept (Y) or reject (N) each update. When done, if a restart is required you will be asked to accept (Y) or postpone (N) it:
3.9) You can always check if restart is pending and required with
Get-WURebootStatus
3.10) To automatically accept all updates to be installed add parameter
-AcceptAll. To automatically accept a restart if required you can also add
-AutoReboot:
Get-WUInstall -MicrosoftUpdate -AcceptAll -AutoReboot
Warning
When using -AutoReboot switch, avoid working with sensitive, important documents while PSWindowsUpdate is updating Windows.
AutoReboot does not give any warning; when updates / upgrades have been initialized Windows will restart without warning causing loss of all unsaved data.
3.11) Feature upgrades like for instance
Windows Insider builds are shown and can be hidden or unhidden exactly as any other update. Notice that for reasons unknown to me feature upgrade sizes are shown wrong, for instance
Build 16170 upgrade is under 3 GB download, not almost 150 GB as PSWindowsUpdate shows:
Note
Notice that when installing a build upgrade with PSWindowsUpdate, restart does not yet finalize upgrade. When you have restarted from PowerShell after PSWindowsUpdate has downloaded and installed build upgrade, it is in fact only initialized, not installed.
You must restart once more from Start > Power > Update and restart
Part Four
Check Update History, Uninstall an Update
4.1) To check your update history use following cmdlet:
Get-WUHistory
4.2) Uninstall an update using either its title or KB ID as shown in steps
3.4 &
3.5:
Get-WUUninstall -KBArticleID "KB4013867" -Confirm:$False
-- OR --
Get-WUUninstall -Title "Microsoft Silverlight*" -Confirm:$False
5.1) To get help, correct command syntax and examples about usage of a cmdlet, normal PowerShell help is available.
For instance to get help with
Hide-WUUpdate cmdlet enter the following cmdlet:
Get-Help Hide-WUUpdate
Notice that when
Get-Help is run first time it needs to be updated (cmdlet
Update-Help run). Accept it with
Y, this is one time only process not required with further use of Get-Help cmdlet:
That's it geeks! Please post all your concerns, questions and issues with PSWindowsUpdate in this thread.
Kari