首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell -安装Windows更新?

Powershell -安装Windows更新?
EN

Stack Overflow用户
提问于 2013-03-02 21:34:05
回答 2查看 21.7K关注 0票数 6

这个是可能的吗?

我想我们需要以某种方式调用WUAgent来运行检测,但我希望从本质上下载并安装更新,然后作为脚本的一部分重新启动。

这将是一个更大的脚本的一部分,基本上通过Powershell构建一个普通的2008R2盒子到一个DC。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-02 21:45:59

看看PowerShell的PSWindowsUpdate模块。

它位于here at the Script Center

票数 9
EN

Stack Overflow用户

发布于 2016-07-19 19:40:43

我建议使用这个脚本

代码语言:javascript
复制
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 }

来源:https://gist.github.com/jacobludriks/9ca9ce61de251a5476f1

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15175054

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档