【问题标题】:Powershell Unable to Install .MSU filesPowershell 无法安装 .MSU ​​文件
【发布时间】: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


【解决方案1】:

foreach 循环和 .msu 文件顺序是问题所在。更新必须按特定顺序进行。将更新重命名为 1.KB3020369.msu、2.KB3172605.msu 和 3.KB3125574.msu。

找到了应用 .msu 更新的新方法 https://harshilsharma63.wordpress.com/2014/12/27/how-to-install-multiple-msu-windows-update-files-with-powershell-script/

<###########

CONFIGURATION TO INSTALL WINDOWS PATCH

###########>

$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
$dir = (Get-Item -Path $dir -Verbose).FullName
Foreach($item in (ls $dir *.msu -Name))
{
    echo $item
    $item = $dir + "\" + $item
    wusa $item /quiet /norestart | Out-Null
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 2016-10-15
    • 1970-01-01
    相关资源
    最近更新 更多