Windows Update - Execute Windows Update via modules and PowerShell - superseded
Log In or Register to download the BES file, and more.

0 Votes


Description

This install the latest Windows updates.

Tested on Windows 10 v1709 with Powershell 5.1.  By the prerequisites mentioned, this will probably work on Windows 7+ and Server 2008 R2+ with PowerShell versions over 2.0.  If the module author hasn't updates his prerequisites, more likely to run on PS 3.0+.

  1. Checks for existing scripting policy LGPO registry item (cannot override GPO)
  2. If exists, back up and disable existing policy
  3. Install prerequisite: NuGet 2.8.5.201+
  4. Install Windows Update PowerShell Module v2.0.0.4 (tested, feel free to drop that requirement)
  5. Run Windows Update via newly added module
  6. (Optionally) Uninstall Windows Update PowerShell Module

It will not ask questions, and not provide options - it will simply install everything it is able to install in one round.

This version will NOT install Windows Feature Updates, such as Windows 10 version 1803.

By running this task you accept the Microsoft TechNet terms of use.

Module Credit Michal Gajda, source: https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc/


Property Details

ID25524
StatusBeta - Preliminary testing ready for more
TitleWindows Update - Execute Windows Update via modules and PowerShell
SourceInternal
Source Release Date6/13/2018 12:00:00 AM
KeywordsWindows Update Powershell Module MichalGajda
Is TaskTrue
Added by on 6/13/2018 3:09:41 PM
Last Modified by on 6/14/2018 3:49:03 PM
Counters 742 Views / 11 Downloads
User Rating 1 star 2 star 3 star 4 star 5 star * Average over 0 ratings. ** Log In or Register to add your rating.

Relevance

isWindows (Relevance 1172)
Used in 1113 fixlets and 524 analyses   * Results in a true/false
Show indented relevance
windows of operating system

Actions

Action 1 (default)

Action Link Click here to install Windows + Microsoft Updates without rebooting or notifying the user.
Script Type BigFix Action Script
// Set Powershell
parameter "PowerShellexe"="{value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of x64 registry}"
// Disable script protection
if {exist (value "EnableScripts" of it = "0") of key "HKLM\Software\Policies\Microsoft\Windows\PowerShell" of native registry}
wait cmd /c reg delete "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScripts" /f
wait cmd /c reg add "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScriptsBackup" /t REG_DWORD /d 00000001 /f
endif

// Install PowerShell Modules from PSGallery
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force"
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Install-Module -Name PSWindowsUpdate -RequiredVersion 2.0.0.4 -Force"
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Import-Module -Name PSWindowsUpdate -Force"

// Check for and install Windows Updates
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Get-WindowsUpdate -Install -MicrosoftUpdate -AcceptAll -IgnoreReboot -Confirm:$false"

// Re-enable script protection
if {exist (value "EnableScriptsbackup" of it = "1") of key "HKLM\Software\Policies\Microsoft\Windows\PowerShell" of native registry}
wait cmd /c reg delete "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScriptsBackup" /f
wait cmd /c reg add "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScripts" /t REG_DWORD /d 00000000 /f
endif
Success Criteria

This action will be considered successful when the applicability relevance evaluates to false.

Action 2

Action Link Click here to install Windows + Microsoft Updates and automatically reboot without asking to reboot.
Script Type BigFix Action Script
// Set Powershell
parameter "PowerShellexe"="{value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of x64 registry}"
// Disable script protection
if {exist (value "EnableScripts" of it = "0") of key "HKLM\Software\Policies\Microsoft\Windows\PowerShell" of native registry}
wait cmd /c reg delete "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScripts" /f
wait cmd /c reg add "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScriptsBackup" /t REG_DWORD /d 00000001 /f
endif

// Install PowerShell Modules from PSGallery
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force"
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Install-Module -Name PSWindowsUpdate -RequiredVersion 2.0.0.4 -Force"
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Import-Module -Name PSWindowsUpdate -Force"

// Check for and install Windows Updates
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Get-WindowsUpdate -Install -MicrosoftUpdate -AcceptAll -AutoReboot -Confirm:$false"

// Re-enable script protection
if {exist (value "EnableScriptsbackup" of it = "1") of key "HKLM\Software\Policies\Microsoft\Windows\PowerShell" of native registry}
wait cmd /c reg delete "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScriptsBackup" /f
wait cmd /c reg add "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScripts" /t REG_DWORD /d 00000000 /f
endif
Success Criteria

This action will be considered successful when the applicability relevance evaluates to false.

Action 3

Action Link Click here to install Windows Updates and automatically reboot without asking to reboot.
Script Type BigFix Action Script
// Set Powershell
parameter "PowerShellexe"="{value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of x64 registry}"
// Disable script protection
if {exist (value "EnableScripts" of it = "0") of key "HKLM\Software\Policies\Microsoft\Windows\PowerShell" of native registry}
wait cmd /c reg delete "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScripts" /f
wait cmd /c reg add "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScriptsBackup" /t REG_DWORD /d 00000001 /f
endif

// Install PowerShell Modules from PSGallery
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force"
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Install-Module -Name PSWindowsUpdate -RequiredVersion 2.0.0.4 -Force"
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Import-Module -Name PSWindowsUpdate -Force"

// Check for and install Windows Updates
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Get-WindowsUpdate -Install -AcceptAll -AutoReboot -Confirm:$false"

// Re-enable script protection
if {exist (value "EnableScriptsbackup" of it = "1") of key "HKLM\Software\Policies\Microsoft\Windows\PowerShell" of native registry}
wait cmd /c reg delete "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScriptsBackup" /f
wait cmd /c reg add "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScripts" /t REG_DWORD /d 00000000 /f
endif
Success Criteria

This action will be considered successful when the applicability relevance evaluates to false.

Action 4

Action Link Click here to install Windows Updates without rebooting or notifying the user.
Script Type BigFix Action Script
// Set Powershell
parameter "PowerShellexe"="{value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of x64 registry}"
// Disable script protection
if {exist (value "EnableScripts" of it = "0") of key "HKLM\Software\Policies\Microsoft\Windows\PowerShell" of native registry}
wait cmd /c reg delete "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScripts" /f
wait cmd /c reg add "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScriptsBackup" /t REG_DWORD /d 00000001 /f
endif

// Install PowerShell Modules from PSGallery
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force"
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Install-Module -Name PSWindowsUpdate -RequiredVersion 2.0.0.4 -Force"
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Import-Module -Name PSWindowsUpdate -Force"

// Check for and install Windows Updates
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Get-WindowsUpdate -Install -AcceptAll -IgnoreReboot -Confirm:$false"

// Re-enable script protection
if {exist (value "EnableScriptsbackup" of it = "1") of key "HKLM\Software\Policies\Microsoft\Windows\PowerShell" of native registry}
wait cmd /c reg delete "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScriptsBackup" /f
wait cmd /c reg add "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScripts" /t REG_DWORD /d 00000000 /f
endif
Success Criteria

This action will be considered successful when the applicability relevance evaluates to false.

Action 5

Action Link Click here to go to the TechNet page on this PowerShell module.
Script Type URL
https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc/
    

Action 6

Action Link Click here to uninstall the PowerShell module.
Script Type BigFix Action Script
// Set Powershell
parameter "PowerShellexe"="{value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of x64 registry}"
// Disable script protection
if {exist (value "EnableScripts" of it = "0") of key "HKLM\Software\Policies\Microsoft\Windows\PowerShell" of native registry}
wait cmd /c reg delete "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScripts" /f
wait cmd /c reg add "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScriptsBackup" /t REG_DWORD /d 00000001 /f
endif

// Install PowerShell Modules from PSGallery
waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -Command "Uninstall-Module -Name PSWindowsUpdate -Force"

// Re-enable script protection
if {exist (value "EnableScriptsbackup" of it = "1") of key "HKLM\Software\Policies\Microsoft\Windows\PowerShell" of native registry}
wait cmd /c reg delete "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScriptsBackup" /f
wait cmd /c reg add "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScripts" /t REG_DWORD /d 00000000 /f
endif
Success Criteria

This action will be considered successful when the applicability relevance evaluates to false.


Sharing

Social Media:
Share this page on Yammer

Comments

Log In or Register to leave comments!