# --- Author: zetod1ce (github.com/ztd38f) --- # # --- DISCLAIMER: Provided as-is, without warranties. For educational and testing use only in controlled environments. Use at your own risk. --- # [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # ============================== # === 1. Проверка прав === # ============================== if (!([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole( [Security.Principal.WindowsBuiltinRole]::Administrator)) { Write-Warning "Запусти PowerShell от имени администратора!" sleep 3 pause } # ============================== # === 2. Подготовка окружения === # ============================== $session=New-Object -ComObject Microsoft.Update.Session;$searcher=$session.CreateUpdateSearcher();$result=$searcher.Search("IsInstalled=0 and IsHidden=0");$updates=New-Object -ComObject Microsoft.Update.UpdateColl; $result.Updates | % { $updates.Add($_) | Out-Null }; if ($updates.Count -gt 0) { $installer=$session.CreateUpdateInstaller(); $installer.Updates=$updates; $installer.Install() } $LogPath = "$env:SystemRoot\Logs\DriverUpdate_$(Get-Date -Format 'yyyyMMdd_HHmmss').log" Write-Host "Лог записывается в: $LogPath" -f DarkGray Write-Output "`n===== START $(Get-Date) =====`n" | Out-File -FilePath $LogPath -Encoding UTF8 -Append # Проверяем и устанавливаем модуль PSWindowsUpdate if (!(Get-Module -ListAvailable -Name PSWindowsUpdate)) { Write-Host "Устанавливаю модуль PSWindowsUpdate..." -f Yellow Install-PackageProvider -Name NuGet -Force -ErrorAction SilentlyContinue Install-Module -Name PSWindowsUpdate -Force -ErrorAction Stop } Import-Module PSWindowsUpdate # Добавляем Microsoft Update (чтобы обновления драйверов были от OEM) if (!(Get-WUServiceManager | Where-Object {$_.ServiceID -like "*Microsoft Update*"})) { Write-Host "Подключаю Microsoft Update..." -f Yellow Add-WUServiceManager -MicrosoftUpdate -Confirm:$false | Out-Null } # ============================== # === 3. Проверка обновлений === # ============================== Write-Host "`nПроверяю наличие обновлений драйверов..." -f Cyan $Drivers = Get-WindowsUpdate -MicrosoftUpdate -Category Drivers -IgnoreReboot -ErrorAction SilentlyContinue if (!($Drivers)) { Write-Host "Все драйверы актуальны. Обновления не требуются." -f Green Write-Output "No driver updates found." | Out-File -FilePath $LogPath -Append pause } # ============================== # === 4. Отображение найденного === # ============================== Write-Host "`nНайдены обновления драйверов:" -f Yellow $Drivers | Select-Object -Property Title, KB, Size, MsrcSeverity | Format-Table -AutoSize $Count = $Drivers.Count Write-Host "`nНайдено $Count драйвер(ов). Установить их?" -f Cyan $Confirm = Read-Host "Введите Y (да) или N (нет)" if ($Confirm -ne 'Y' -and $Confirm -ne 'y') { Write-Host "Установка отменена пользователем." -f Red Write-Output "User cancelled update." | Out-File -FilePath $LogPath -Append pause } # ============================== # === 5. Установка драйверов === # ============================== Write-Host "`nНачинаю установку драйверов..." -f Cyan Install-WindowsUpdate -MicrosoftUpdate -Category Drivers -AcceptAll -IgnoreReboot -Verbose -ErrorAction Continue | Tee-Object -FilePath $LogPath -Append Write-Host "`nУстановка драйверов завершена." -f Green # ============================== # === 6. Завершение === # ============================== Write-Host "`nХотите перезагрузить компьютер сейчас?" -f Cyan $Reboot = Read-Host "Введите Y (да) или N (нет)" if ($Reboot -eq 'Y' -or $Reboot -eq 'y') { Write-Host "Перезагрузка..." -f Yellow Restart-Computer } else { Write-Host "Перезагрузка отложена." -f Green } Write-Output "`n===== END $(Get-Date) =====`n" | Out-File -FilePath $LogPath -Append