{"id":1159,"date":"2016-12-14T18:23:30","date_gmt":"2016-12-14T22:23:30","guid":{"rendered":"http:\/\/mikemartinezonline.com\/blog\/?p=1159"},"modified":"2016-12-14T18:23:30","modified_gmt":"2016-12-14T22:23:30","slug":"using-powershell-to-manage-windows-updates","status":"publish","type":"post","link":"https:\/\/mikemartinezonline.com\/blog\/2016\/12\/14\/using-powershell-to-manage-windows-updates\/","title":{"rendered":"Using PowerShell to Manage Windows Updates"},"content":{"rendered":"<p><b>Using PowerShell to Manage Windows Updates:&#160; PSWindowsUpdate<\/b><\/p>\n<p>Often we have to update computers that have not \u2013 for whatever reason been updated in a long time. AND we often have to create new deploy images using sysprep. What usually happens is that Windows update will hang at \u2018checking for updates\u2019 for a very long time and either error out or never complete. A secret I found to deploying Windows Updates when this happens or from within Audit Mode is an excellent PowerShell module created by Michal Gajda. This module, aptly called <b>PSWindowsUpdate<\/b>, allows managing Windows Update on any computer running PowerShell 2.0 or higher. This module even enables Windows admins to check for and install updates on remote PCs and servers. PSWindowsUpdate is particularly handy for installing updates on Server Core machines that have no GUI, or in instances such as Sysprep\u2019s Audit Mode where the Windows Update GUI doesn\u2019t work.<\/p>\n<p>\u00b7 Get started by <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/2d191bcd-3308-4edd-9de2-88dff796b0bc\/\">downloading the latest version of PSWindowsUpdate.zip<\/a>.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb.png\" width=\"457\" height=\"232\" \/><\/a><\/p>\n<p>\u00b7 Once downloaded, extract the contents of the zip file to C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\Modules\\.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-1.png\" width=\"468\" height=\"346\" \/><\/a><\/p>\n<p><i>Extracting files from PSWindowsUpdate.zip.<\/i><\/p>\n<p>\u00b7 Click <b>Continue <\/b>if a UAC prompt appears.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-2.png\" width=\"473\" height=\"238\" \/><\/a><\/p>\n<p>\u00b7 When the files have been extracted into the PowerShell Modules folder, open an elevated PowerShell prompt. Change PowerShell\u2019s Execution Policy to <b>RemoteSigned<\/b>. The RemoteSigned Execution Policy allows PowerShell scripts downloaded from the Internet to run on a PC as long as they are signed by a trusted publisher.<\/p>\n<p>\u00b7 Type <b>Set-ExecutionPolicy RemoteSigned<\/b> and press <b>Enter<\/b>. When prompted, confirm the change by pressing <b>Y<\/b> and then <b>Enter<\/b>.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-3.png\" width=\"506\" height=\"305\" \/><\/a><\/p>\n<p><i>Changing PowerShell\u2019s execution policy<\/i><\/p>\n<p>This completes the one-time configuration of the module! Now it\u2019s time to put PSWindowsUpdate to use!<\/p>\n<p>\u00b7 If running PowerShell v2.0, type <b>Import-Module PSWindowsUpdate<\/b> and hit <b>Enter<\/b>. This isn\u2019t necessary in PowerShell v3 and higher, but it doesn\u2019t hurt anything either. This step simply guarantees that the modules cmdlets will be available to the PowerShell v2.0 session.<\/p>\n<p>\u00b7 Display a list of all the module\u2019s available cmdlets by typing <b>Get-Command \u2013module PSWindowsUpdate<\/b> and hitting <b>Enter<\/b>.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-4.png\" width=\"482\" height=\"291\" \/><\/a><\/p>\n<p><i>Using Get-Command -module PSWindowsUpdate.<\/i><\/p>\n<p>\u00b7 Possibly the most important function for getting and installing updates is <b>Get-WUInstall<\/b>. Help for each cmdlet is available, so to see full help for Get-WUInstall type <b>Help Get-WUInstall \u2013full<\/b> and press <b>Enter<\/b>.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-5.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-5.png\" width=\"490\" height=\"231\" \/><\/a><\/p>\n<p><i>Looking at help for Get-WUInstall.<\/i><\/p>\n<p>When applying updates, I prefer connecting to the Microsoft Update servers. Using these instead of the standard Windows Update servers allows installing updates to Office and other Microsoft products in addition to the normal Windows updates. Unfortunately, trying to connect to the Microsoft Update servers using the PSWindowsUpdate module from a fresh Windows installation will produce an error, as shown below.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-6.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-6.png\" width=\"452\" height=\"334\" \/><\/a><\/p>\n<p>\u00b7 The reason for this error is because Windows is registered to use only the standard Windows Update servers by default. To use the Microsoft Update servers, the Microsoft Update Service must be registered on the computer. In the GUI, this is done by selecting the checkbox for <b>Give me updates for other Microsoft products when I update Windows<\/b> from the Control Panel \u2013 Windows Update \u2013 Change Settings applet.<\/p>\n<p>\u00b7 In the PSWindowsUpdate module, the same process is completed by using the Add-WUServiceManager cmdlet with the ServiceID for the Microsoft Update service specified. Type <b>Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d<\/b> and press <b>Enter<\/b>. When prompted, confirm registering the service by typing <b>Y<\/b> and pressing <b>Enter<\/b> one more time.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-7.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-7.png\" width=\"491\" height=\"369\" \/><\/a><\/p>\n<p><i>Registering the Microsoft Update servers.<\/i><\/p>\n<p>\u00b7 List available updates from the Microsoft Update servers by typing <b>Get-WUInstall \u2013MicrosoftUpdate \u2013ListOnly<\/b> and pressing <b>Enter<\/b>. After a few moments, the system will return a list of the available updates for the current machine. No error this time!<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-8.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-8.png\" width=\"454\" height=\"342\" \/><\/a><\/p>\n<p>\u00b7 The same results are produced by typing <b>Get-WUList \u2013MicrosoftUpdate<\/b> and pressing <b>Enter<\/b>.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-9.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-9.png\" width=\"465\" height=\"350\" \/><\/a><\/p>\n<p>\u00b7 Type <b>Get-WUInstall \u2013MicrosoftUpdate<\/b> and press <b>Enter<\/b> to go through the available updates, confirming installation of each one manually.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-10.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-10.png\" width=\"488\" height=\"347\" \/><\/a><\/p>\n<p><b>PSWindowsUpdate and Parameter Support<\/b><\/p>\n<p>Another awesome feature of the PSWindowsUpdate module is its support of parameters. For example, using the <b>\u2013AcceptAll<\/b>and the <b>\u2013AutoReboot<\/b> parameters with the Get-WUInstall cmdlet changes the manual process into an automated one. Type <b>Get-WUInstall \u2013MicrosoftUpdate \u2013AcceptAll \u2013AutoReboot<\/b> and press <b>Enter<\/b>. The system will download and install all available updates and then automatically reboot if any of the updates require a reboot.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-11.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-11.png\" width=\"494\" height=\"337\" \/><\/a><\/p>\n<p><i>Retrieving updates and installing automatically.<\/i><\/p>\n<p>Don\u2019t want a particular update to be installed? No problem! Use <b>Hide-WUUpdate<\/b>. Selection parameters such as <b>\u2013Title<\/b> or <b>\u2013KBArticleID<\/b> narrow in and hide specific updates. Feel free to use wildcards with these parameters. As an example, type <b>Hide-WUUpdate \u2013Title \u201cBing*\u201d \u2013KBArticleID \u201cKB2673774\u201d \u2013MicrosoftUpdate \u2013Confirm:$false<\/b> and press <b>Enter<\/b> to hide the Bing Bar 7.3 update.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-12.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-12.png\" width=\"472\" height=\"357\" \/><\/a><\/p>\n<p><i>Hiding an unwanted update.<\/i><\/p>\n<p>Notice that I used the <b>\u2013Confirm<\/b> parameter, along with the <b>$false<\/b> switch, to automatically confirm hiding the selected update. In the future the update won\u2019t appear when listing available updates.<\/p>\n<p>Did you make a mistake and hide the wrong update? No problem! <b>Hide-WUUpdate<\/b> can unhide an update by using the \u2013HideStatus parameter with the $false switch. To unhide the update hidden earlier, type <b>Hide-WUUpdate \u2013Title \u201cBing*\u201d \u2013KBArticleID \u201cKB2673774\u201d \u2013MicrosoftUpdate \u2013HideStatus:$false \u2013Confirm:$false<\/b> then press <b>Enter<\/b>. As before, I used the \u2013Confirm:$false parameter to keep everything streamlined.<\/p>\n<p><a href=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image-13.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/mikemartinezonline.com\/blog\/wp-content\/uploads\/2016\/12\/image_thumb-13.png\" width=\"473\" height=\"356\" \/><\/a><\/p>\n<p><i>Unhiding a previously hidden update.<\/i><\/p>\n<p>Once all the updates are complete make sure to open PowerShell (as Administrator) and set the Execution Policy back to \u2018restricted\u2019:<\/p>\n<p>Type <b>Set-ExecutionPolicy Restricted<\/b> and press Enter. Then exit<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using PowerShell to Manage Windows Updates:&#160; PSWindowsUpdate Often we have to update computers that have not \u2013 for whatever reason been updated in a long time. AND we often have to create new deploy images using sysprep. What usually happens is that Windows update will hang at \u2018checking for updates\u2019 for a very long time &hellip; <a href=\"https:\/\/mikemartinezonline.com\/blog\/2016\/12\/14\/using-powershell-to-manage-windows-updates\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using PowerShell to Manage Windows Updates&#8221;<\/span><\/a><\/p>\n","protected":false},"author":587,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[18,13,186,256,15,218,257],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/mikemartinezonline.com\/blog\/wp-json\/wp\/v2\/posts\/1159"}],"collection":[{"href":"https:\/\/mikemartinezonline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mikemartinezonline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mikemartinezonline.com\/blog\/wp-json\/wp\/v2\/users\/587"}],"replies":[{"embeddable":true,"href":"https:\/\/mikemartinezonline.com\/blog\/wp-json\/wp\/v2\/comments?post=1159"}],"version-history":[{"count":1,"href":"https:\/\/mikemartinezonline.com\/blog\/wp-json\/wp\/v2\/posts\/1159\/revisions"}],"predecessor-version":[{"id":1160,"href":"https:\/\/mikemartinezonline.com\/blog\/wp-json\/wp\/v2\/posts\/1159\/revisions\/1160"}],"wp:attachment":[{"href":"https:\/\/mikemartinezonline.com\/blog\/wp-json\/wp\/v2\/media?parent=1159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikemartinezonline.com\/blog\/wp-json\/wp\/v2\/categories?post=1159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikemartinezonline.com\/blog\/wp-json\/wp\/v2\/tags?post=1159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}