windows - 如何测试Windows Server是否完全更新? (尝试创建更新/重启循环脚本)

标签 windows powershell workflow windows-server-2012-r2 windows-update

虽然我通常使用 Windows 服务器的预烘焙镜像,但偶尔会遇到这样的情况:我必须从头开始设置一个镜像,并经历检查更新、安装更新然后重新启动的极其繁琐的过程。很多很多很多次。

我正在尝试编写一个简单的脚本来自动执行此操作。

检查和安装更新非常简单:

wuauclt.exe /detectnow /updatenow

重启也同样简单:

shutdown /r /t 0

但我想做的是创建一个 PowerShell 工作流程,在重新启动后继续运行,循环运行上述命令。

我还没有弄清楚的领域是:

  • 如何检查更新是否已完成。
  • 如何测试是否没有剩余更新可供安装(AKA Windows 已完全更新并且脚本可以停止)。

最佳答案

使用 update searcher检查待处理的更新:

$criteria = "Type='software' and IsAssigned=1 and IsHidden=0 and IsInstalled=0"

$searcher = (New-Object -COM Microsoft.Update.Session).CreateUpdateSearcher()
$updates  = $searcher.Search($criteria).Updates

if ($updates.Count -ne 0) {
  # $updates pending
} else {
  # system up-to-date
}

关于windows - 如何测试Windows Server是否完全更新? (尝试创建更新/重启循环脚本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30968999/

相关文章:

c# - 在没有 SolidColorBrush 的情况下从 Color 获取 Brush

build - 在TFS 2010中获取已触发构建的变更集编号

git - 使用 git-flow 功能分支和 Gerrit 的工作流

windows - 使用 PowerShell 设置十六进制注册表值

windows - "Not enough storage to process this command. (8)"我无法休眠

exception - 电源外壳 2 : How to determine what exceptions a cmdlet can throw?

powershell - 在文本文件中交换 last.first 到 first.last

PayPal Express Checkout - 如何正确获取送货地址(用于计算运费)?

windows - 从 Windows 驱动程序控制 COM 端口名称

datetime - 为什么 Get-Date 似乎返回 DateTime 对象,但 BinarySerializer 表明它返回一个 PSObject?