【发布时间】:2016-12-13 02:44:33
【问题描述】:
我目前正在尝试将此站点的过程更改为脚本以自动化该过程。 http://www.freenode-windows.org/resources/vista-7/windows-update
当我检查“控制面板”>“系统和安全”>“Windows 更新”>“查看更新历史记录”时,更新 KB3020369、KB3172605 和 KB3125574 未显示为已安装。我的 foreach 循环有问题吗?
<########
CONFIGURATION TO STOP WINDOWS UPDATES
#########>
$rmpth = 'c:\windows\softwaredistribution\WuRedir'
$ws = get-service wuauserv
if($ws.Status -eq "Stopped"){
msg * "Update Service Stopped"
}else{
stop-service wuauserv -Force
msg * "Stopping Update Service, Update Service Stopped"
}
if(test-path $rmpth){
remove-item $rmpth -Force -Confirm:$false
}
<###########
CONFIGURATION TO INSTALL WINDOWS PATCH
###########>
$pathofupdates = @("KB3020369", "KB3172605", "KB3125574")
Foreach($item in $pathofupdates)
{
$wusainit = "/quiet /norestart C:\temp\Windows /extract C:\temp\Windows\${item}.msu"
$disminit = "/online /quiet /norestart /add-package /PackagePath:C:\temp\Windows\${disminit}.cab"
$SB={ Start-Process -FilePath 'wusa.exe' -ArgumentList $wusainit.ToString() -Wait -PassThru }
Invoke-Command -ScriptBlock $SB
$SB={ Start-Process -FilePath 'dism.exe' -ArgumentList $disminit.ToString() -Wait -PassThru }
Invoke-Command -ScriptBlock $SB
}
【问题讨论】:
-
别忘了问你的问题(“看起来不像实际安装”很模糊)。
-
谢谢你,比尔。所做的更改。如果还需要澄清,请告诉我。
标签: powershell