Powershell 在 AD 计算机上运行 Windows 更新命令

Powershell 在 AD 计算机上运行 Windows 更新命令

所以我的目标是运行如下命令get-adcomputer | Install-WindowsUpdate -AcceptAll -AutoReboot

我想获取所有 AD 计算机并将 ComputerName 传递到 中的 ComputerName 属性Install-WindowsUpdate。我尝试了 @foreach 语句,但它需要很长时间才能运行,因为它一次只执行一个。我希望它能同时执行多台计算机。

有任何想法吗?

答案1

所以我最终做的是从 Get-ADcomputer 创建一个计算机变量。我通过管道传递一个 select 语句来获取属性“Name”,这样就成功了。然后我将变量插入命令中:

$computer = Get-ADComputer -SearchBase "OU=Computers,DC=my,DC=domain,DC=com" -Filter 'Name -like "*vdi*"' | Select -ExpandProperty name
Get-windowsupdate -ComputerName $computer -AcceptAll -Install -AutoReboot

为了使其正常工作,您必须确保所有计算机都安装了 PSWindowsUpdate、Enable-WURemoting 和 set-executionpolicy 不受限制,对此我并不感到兴奋。

希望这对其他人有帮助。

相关内容