0

Worked out how to script install of .msu updates.

$filename = "C:\temp\log\WUInstall_" + $timer + ".evtx"
Start-Process -FilePath wusa -ArgumentList "\\fs1\software\WS2012R2\windows8.1-kb4041693-x64_31e473824b705bf05f3befc423d39fa0c6d0fb49.msu /quiet /norestart /log:$filename" -Wait

Using wusa with Powershell as this is the only way to avoid a machine restart after the update - as I need to wait for this one to complete and run a couple more commands, before issuing a manual restart (/norestart requires /quiet as well). Not able to log the outcome of the installation to a clear-text format, it's .evtx only.

Let's just say that the update is already installed (could be an already patched OS image, no control over this) and I run the script. It just runs, no error. When executed without /quiet /norestart it will eventually print "<..> is already installed on this computer." Also, in .evtx log there are a few lines that show the status of the install process, including "InstallWorker.01090: Update is already installed". But I have no knowledge on how to parse this log. I can only parse a plain text log.

Is there a way to parse the .evtx log ? so that I can put some logic in my script to check the status (update installed ok or not) and decide on an action ? (move to next step in the script or quit with error)

Or a better solution to solve this in Powershell 5.1 ? Should be able to apply it to WS 2012 through 2016.

2 Answers 2

1
Get-WinEvent -Path $PathToFile

That should work assuming it's really a .evtx file.

1
  • Thank you. This doesn't work with my log file, but is able to open an export file from Event Viewer. Guess the format is different. I can open the wusa log with Event Viewer though... Also found the tracerpt command, but couldn't figure out the correct config to parse the log generated by wusa. Oct 23, 2017 at 14:42
1

First, I am pretty sure that the log file generated by that would not be anything other than an ASCII format log file. Naming it .evtx only makes it confusing.

Rather than parsing a log file to look for known lines, the function that is built for whether the command succeeded or failed is the return code or exit code. This should get you started:

$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $commandPath
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = $commandArguments
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
[pscustomobject]@{
    commandTitle = $commandTitle
    stdout = $p.StandardOutput.ReadToEnd()
    stderr = $p.StandardError.ReadToEnd()
    ExitCode = $p.ExitCode  
}
$p.WaitForExit()

After you get the return code, this may be helpfull:

https://support.microsoft.com/en-us/help/938205/windows-update-error-code-list

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .