Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install all pending windows updates #9

Open
JayRHa opened this issue Feb 11, 2023 · 1 comment
Open

install all pending windows updates #9

JayRHa opened this issue Feb 11, 2023 · 1 comment
Labels
idea New ideas

Comments

@JayRHa
Copy link
Owner

JayRHa commented Feb 11, 2023

No description provided.

@andrew-s-taylor andrew-s-taylor added the idea New ideas label Mar 8, 2023
@najki78
Copy link

najki78 commented Mar 10, 2023

I have just finished a script that creates a scheduled task which runs Windows Update and then auto-reboot. I will polish it an create a pull request. Meanwhile, the core code:

# NuGet
$packageprovider = Get-PackageProvider -Name nuget -ListAvailable -Verbose -ErrorAction SilentlyContinue

# If not installed, download and install it from PSGallery repository
if (-not $packageprovider) {
    # Install NuGet provider if needed
    Install-PackageProvider -Name NuGet -Scope AllUsers -Verbose -Force -confirm:$false -ErrorAction SilentlyContinue 
}

Import-PackageProvider nuget -Verbose -Force -ErrorAction SilentlyContinue

# Check if PSWindowsUpdate module is already installed
$module = Get-Module -Name PSWindowsUpdate -ListAvailable -Verbose -ErrorAction SilentlyContinue

# If not installed, download and install it from PSGallery repository
if (-not $module) {
    # Install PSWindowsUpdate module for all users
    Install-Module -Name PSWindowsUpdate -Scope AllUsers -AllowClobber -Verbose  -Force -confirm:$false -ErrorAction SilentlyContinue
}

# Import PSWindowsUpdate module
Import-Module -Name PSWindowsUpdate -Scope Global -Verbose -ErrorAction SilentlyContinue

Write-Host "WindowsUpdate service"
$WindowsUpdateService = Get-Service -Name wuauserv -Verbose -ErrorAction SilentlyContinue

if( $WindowsUpdateService.StartType -eq "Disabled"){
    Set-Service -Name wuauserv -StartupType Manual -ErrorAction SilentlyContinue
}

if( $WindowsUpdateService.Status -ne "Running"){
    Start-Service -Name wuauserv -ErrorAction SilentlyContinue
}

# to exclude drivers, use parameter -NotCategory "Drivers"
Get-WindowsUpdate -NotCategory "Drivers" -Download -AcceptAll -Verbose -ErrorAction SilentlyContinue -Silent
Install-WindowsUpdate -NotCategory "Drivers" -AcceptAll -AutoReboot -Verbose -ErrorAction SilentlyContinue

Or alternatively, to include check if reboot is necessary:

Install-WindowsUpdate -AcceptAll -NoRestart -AutoReboot -Verbose -ErrorAction SilentlyContinue 
# check if Reboot is Required, if yes, Restart-Computer -Force
if ( (Get-WURebootStatus).RebootRequired ) { Restart-Computer -Force } 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea New ideas
Projects
None yet
Development

No branches or pull requests

3 participants