Simple Script to find MSI errors

Here’s a simple PowerScript to pull out MSI errors out of the EventViewer and the MSI logs.

Baiscally the script first clears the log file then clears everything out of the Temp directory. Next the script prompts for the admin to start the installation, once you are done installing the program click ok to continue. The script will then collect the error messages from the MSI logs and the last three windows installer entries from the EventViewer. If there are no errors then it will return sucessful installs entries from the Event Viewer and nothing from the logs. In short this script is just a time saver from having to dig though the event logs and the temp directory for the msi logs and then having to go through those long MSI logs. Troubleshooting the error codes will still need to happen outside of the script.

Be sure to enable Windows Installer logging before beginning. This can be set with the following PowerShell command line.

Set-ItemProperty -path “HKLM:\SOFTWARE\Policies\Microsoft\Windows\Installer” -name “Logging” -value voicewarmup

Here’s the final code:

MSIErrorExtractor.ps1

?View Code POWERSHELL
 
Clear-Content errors.txt
 
get-Childitem $env:Temp | remove-Item -force
 
$a = new-object -comobject wscript.shell
$b = $a.popup("Please run installation and click ok once installation is complete",0,"Waiting for MSI Installation and User Input",1)
 
Get-EventLog Application | ? {$_.Source -eq "MSIInstaller" } |  Select-Object TimeGenerated,Source, EntryType, Message -First 3| Format-List | out-file errors.txt
#-and $_.EntryType -eq "Error"
 
filter finderrors { if ($_.contains("Error")) {$_}}
Get-Content $env:temp\MSI*.log | finderrors | Out-File -Append errors.txt | notepad errors.txt