windowspowershellscriptinghotfix

Not able to install Microsoft update (hotfix) - msu through PowerShell script


I am trying to install MSU through below PowerShell script, but its not getting installed. I am not aware of PowerShell scripting. Please someone give me best way to modified this script. I am looking forward to hear.

Start-Process "C:\Installer\windows10.0-kb4520062-x64_9f2a827f11f945d19bd26de6f113f611a38bb8a1.msu" -ArgumentList "/quiet /norestart"

Solution

  • In order to be able to pass arguments to a process launched via Start-Process, the (possibly positionally implied) -FilePath argument must be a true executable, not just a document, which is what a .msu file is.

    Therefore, you must pass the executable that .msu files are registered to be processed by explicitly to -FilePath, which is wusa.exe (note the /quiet /norestart at the end of the -ArgumentList argument):

    Start-Process `
      -FilePath     "$env:SystemRoot\System32\wusa.exe" `
      -ArgumentList 'C:\Installer\windows10.0-kb4520062-x64_9f2a827f11f945d19bd26de6f113f611a38bb8a1.msu /quiet /norestart'
    

    Note:

    However, there is a trick that simplifies the above: pipe the wusa.exe call to Write-Output, which forces it to execute synchronously (as a GUI-subsystem application, wusa.exe would otherwise run asynchronously) and also records its exit code in the automatic $LASTEXITCODE variable:

    # Note the "| Write-Output" at the end of the line,
    # which makes wusa.exe run synchronously and records its process
    # exit code in $LASTEXITCODE.
    & "$env:SystemRoot\System32\wusa.exe" C:\Installer\windows10.0-kb4520062-x64_9f2a827f11f945d19bd26de6f113f611a38bb8a1.msu /quiet /norestart | Write-Output
    
    if ($LASTEXITCODE -ne 0)
      throw "wusa.exe indicates failure; exit code was: $LASTEXITCODE"
    }
    
    'Installation succeeded.'