Skip to content

Commit

Permalink
feat: update drivers through windows update file
Browse files Browse the repository at this point in the history
  • Loading branch information
RadNotRed committed Feb 12, 2025
1 parent 70151ee commit 07d7f67
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@echo off
set "script=%windir%\AtlasModules\Scripts\ScriptWrappers\UpdateDrivers.ps1"

if not exist "%script%" (
echo Script not found: "%script%"
pause
exit /b 1
)

whoami /user | find /i "S-1-5-18" > nul 2>&1 || (
call RunAsTI.cmd "%~f0" %*
exit /b
)

@REM The "echo Y" is to bypass the NuGet installation user prompt.
@REM If there's a better way, feel free to PR.
echo Y | powershell -ExecutionPolicy Bypass -NoProfile -File "%script%"

pause
exit /b 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[CmdletBinding()]
param (
[switch]$RestartAfterUpdate
)

function Install-PSWindowsUpdateModule {
# Make sure that PowerShellGet is updated just in case
if (-not (Get-Module -ListAvailable -Name PowerShellGet)) {
Install-Module -Name PowerShellGet -Force -AllowClobber -Confirm:$false -Scope AllUsers
}

# Making it trusted now will avoid further user prompts in the future
if ((Get-PSRepository -Name PSGallery).InstallationPolicy -ne "Trusted") {
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
}

# Install PSWindowsUpdate
if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
Install-Module -Name PSWindowsUpdate -Force -Scope CurrentUser -Confirm:$false
}
}

function Enable-MicrosoftUpdate {
Write-Host "Enabling Microsoft Update for driver updates..."
Add-WUServiceManager -ServiceID "7971f918-a847-4430-9279-4a52d1efe18d" -AddServiceFlag 7 -Confirm:$false | Out-Null
}

function Update-Drivers {
Write-Host "Checking for driver updates..."
$Updates = Get-WUList -MicrosoftUpdate -Category "Drivers"

if ($Updates.Count -gt 0) {
Write-Host "Installing available driver updates..."
$Updates | Format-Table ComputerName, Status, KB, Size, Title -AutoSize
Get-WUInstall -MicrosoftUpdate -Category "Drivers" -AcceptAll -IgnoreReboot -Confirm:$false | Out-Null
Write-Host "Driver updates installed successfully!"

# Restart if needed
if ($RestartAfterUpdate) {
Write-Host "Restarting the system in 10 seconds..."
Start-Sleep -Seconds 10
Restart-Computer -Force
}
} else {
Write-Host "No driver updates found."
}
}

Install-PSWindowsUpdateModule
Enable-MicrosoftUpdate
Update-Drivers

Write-Host "Driver update process completed."

0 comments on commit 07d7f67

Please sign in to comment.