2013-03-02 20 views
5

Czy to możliwe?Powershell - instaluje aktualizacje systemu Windows?

Sądzę, że musielibyśmy jakoś wywołać WUAgent, aby uruchomić wykrywanie, ale chciałbym zasadniczo pobrać i zainstalować aktualizacje, a następnie zrestartować jako część skryptu.

To będzie część większego skryptu, który w zasadzie zbuduje waniliową skrzynkę 2008R2 aż do DC przez całą moc Powershell.

Odpowiedz

2

Proponuję za pomocą tego skryptu

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 } 

Źródło: https://gist.github.com/jacobludriks/9ca9ce61de251a5476f1

Powiązane problemy