Last active
November 18, 2024 22:14
-
-
Save billpieper/a39173afa0b343a14ddeeb1d79ab14ea to your computer and use it in GitHub Desktop.
PowerShell script that will download and install all Microsoft (Windows) Updates on Windows 10 / Windows Server 2016
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################### | |
############################################################################### | |
##### PowerShell Windows Update Script. | |
##### Leverages Microsoft Update provider to install all missing updates | |
############################################################################### | |
############################################################################### | |
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force | |
Install-PackageProvider -Name NuGet -Force | |
Import-PackageProvider -Name NuGet | |
# Update the PSGallery (the Default) PSRepository | |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted | |
Get-PSRepository -Name PSGallery | Format-List * -Force | |
# List all modules installed | |
Write-Output "Running: Get-InstalledModule" | |
Get-InstalledModule | |
# Install the module we need | |
Write-Output "Running: Install-Module -Name PSWindowsUpdate -Force" | |
Install-Module -Name PSWindowsUpdate -Force | |
# Import the module | |
Import-Module -Name PSWindowsUpdate | |
# List support commands from the module: | |
Get-Command -Module PSWindowsUpdate | |
# Now, check if the Microsoft Update service is available. | |
# If not, we need to add it. | |
$MicrosoftUpdateServiceId = "7971f918-a847-4430-9279-4a52d1efe18d" | |
If ((Get-WUServiceManager -ServiceID $MicrosoftUpdateServiceId).ServiceID -eq $MicrosoftUpdateServiceId) { Write-Output "Confirmed that Microsoft Update Service is registered..." } | |
Else { Add-WUServiceManager -ServiceID $MicrosoftUpdateServiceId -Confirm:$true } | |
# Now, check again to ensure it is available. If not -- fail the script: | |
If (!((Get-WUServiceManager -ServiceID $MicrosoftUpdateServiceId).ServiceID -eq $MicrosoftUpdateServiceId)) { Throw "ERROR: Microsoft Update Service is not registered." } | |
# Force the installation of updates and reboot of server (if required) | |
Get-WUInstall -MicrosoftUpdate -AcceptAll -AutoReboot | |
Get-WUInstall -MicrosoftUpdate -AcceptAll -Download -Install -AutoReboot |
hsaharmony
commented
Feb 13, 2024
via email
Thank you so much for quick response.
…On Tue, Feb 13, 2024, 5:08 PM Bill Pieper ***@***.***> wrote:
*CAUTION: [EXTERNAL EMAIL] *- This email originated from outside of
Harmony Public Schools. Do NOT click links or open attachments unless you
recognize the sender and know the content is safe. ***@***.****
commented on this gist.
------------------------------
It's been 5+ years since I last used this ... I'd be unable to predict
behavior as OS's etc have evolved since then.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/billpieper/a39173afa0b343a14ddeeb1d79ab14ea#gistcomment-4897738>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKN4EUJHJBKDEIBUTIMBG63YTPW5RBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVA4DSNJZGQ2DSMVHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment