2013-03-02 15 views
5

È possibile?PowerShell - Installa aggiornamenti di Windows?

Suppongo che avremmo bisogno di invocare il WUAgent in qualche modo per eseguire un rilevamento, ma vorrei essenzialmente scaricare e installare gli aggiornamenti, quindi riavviare come parte dello script.

Questo farà parte di uno script più grande per costruire fondamentalmente una scatola 2008R2 di vaniglia fino a un controller DC attraverso Powershell.

risposta

2

Io suggerisco di usare questo script

Function WSUSUpdate { 
$Criteria = "IsInstalled=0 and Type='Software'" 
$Searcher = New-Object -ComObject Microsoft.Update.Searcher 
try { 
    $SearchResult = $Searcher.Search($Criteria).Updates 
    if ($SearchResult.Count -eq 0) { 
     Write-Output "There are no applicable updates." 
     exit 
    } 
    else { 
     $Session = New-Object -ComObject Microsoft.Update.Session 
     $Downloader = $Session.CreateUpdateDownloader() 
     $Downloader.Updates = $SearchResult 
     $Downloader.Download() 
     $Installer = New-Object -ComObject Microsoft.Update.Installer 
     $Installer.Updates = $SearchResult 
     $Result = $Installer.Install() 
    } 
} 
catch { 
    Write-Output "There are no applicable updates." 
    } 
} 

WSUSUpdate 
If ($Result.rebootRequired) { Restart-Computer } 

Fonte: https://gist.github.com/jacobludriks/9ca9ce61de251a5476f1

Problemi correlati