Apply service packs (.msu file) update using powershell scripts on local server

半世苍凉 提交于 2019-12-10 11:29:52

问题


What it basically does is the script gets the .msu files from a location and copies to the "C:\temp\" folder. Then the script gets all the .msu files and stores the names in the array. Using the foreach loop it tries to apply the .msu updates to the local server where the script is running.

However when i run the script. It doesn't do anything.

Below is the code

$from="sourceLocation\*.msu"
$to="C:\temp\"
Copy-Item $from $to -Recurse -Force
$listOfMSUs= (Get-ChildItem –Path $to -Filter "*.msu").Name
Write-Host $listOfMSUs

if($listOfMSUs)
{
    foreach($msu in $listOfMSUs)
    {
    Write-Host "Processing The Update"
    &  wusa $to$msu /quiet /norestart         
    }
}
else{

Write-Host "MSUs doesnt exists"
}

Any suggestions please?


回答1:


You're copying the file(s) to a local folder (C:\temp), but run wusa on a remote host. That host may have the same local folder, but you didn't copy the update(s) to that folder. If you want to install the updates from a local folder on a remote host, you must copy them to that folder on the remote host:

Copy-Item $from "\\$hostname\$($to -replace ':','$')" -Recurse -Force

Edit: Since you want to install the updates on the host running the script your code should work in general, although I'd streamline it a little, e.g. like this:

$from = "sourceLocation\*.msu"
$to   = 'C:\temp'

Copy-Item $from $to -Recurse -Force

$updates = @(Get-ChildItem –Path $to -Filter '*.msu')
if ($updates.Count -ge 1) {
  $updates | % {
    Write-Host "Processing update $($_.Name)."
    & wusa $_.FullName /quiet /norestart
  }
} else {
  Write-Host 'No updates found.'
}

Is UAC enabled on the host? In that case you need to run the Script "as Administrator" when running it manually, or with the option "run with highest privileges" checked when running the script as a scheduled task.




回答2:


The answer was simple. All i needed was a /install command parameter. So the line should be

 & wusa /install $to$msu  /quiet /norestart 

 OR

  & wusa $to$msu  /quiet /norestart 


来源:https://stackoverflow.com/questions/21112244/apply-service-packs-msu-file-update-using-powershell-scripts-on-local-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!