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

18,663

Solution 1

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 

Solution 2

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.

Share:
18,663
Sike12
Author by

Sike12

learning to code at the moment.

Updated on June 04, 2022

Comments

  • Sike12
    Sike12 almost 2 years

    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?