Powershell无法安装.MSU文件

时间:2016-12-12 17:23:38

标签: powershell

我目前正在尝试将此站点的操作更改为脚本以自动执行该过程。 http://www.freenode-windows.org/resources/vista-7/windows-update

当我检查控制面板>系统&安全> Windows Update>查看更新历史记录 - 更新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

 }

1 个答案:

答案 0 :(得分:0)

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
}