I’m scripting the installation and configuration procedure for my company’s desktop application. We send out a kiosk and can’t put everything in the installer… moving right along! I’m using Start-Process to wait for msiexec to complete.
function Run-Installer
{
param
(
[string] $msi = $(throw "Required parameter: 'msi'"),
)
if(-not(Test-Path $msi -Type Leaf))
{
throw "The installer could not be found: '$msi'"
}
$name = (Get-Item $msi).BaseName
Write-Host "Installing $name"
$p =
@(
"/I `"$msi`"", # Install this MSI
"/QN", # Quietly, without a UI
"/L*V `"$ENV:TEMP\$name.log`"" # Verbose output to this log
)
Start-Process -FilePath "msiexec" -ArgumentList $p -Wait
}
Where I want to get fancy is with the log output from msiexec. I want to stream the contents of the log to the console while the installer is running. I’m guessing there are multiple parts to the solution
- Running the installer in a background, waitable manner
- Tailing the log file until some condition is met (installer job completes)
- Optional: Filtering the output or writing to debug/verbose for fun
You can remove the job, and unregister the event once the install is done.
Change
Write-HosttoWrite-Verbosefor-VerbosesupportEDIT: I tested my answer while installing an application, and found that it was pretty slow when reading the log file. I updated the
Get-Contentcall to use-ReadCount 100to send the data as arrays of lines. TheWrite-Hostline was updated to handle the arrays.I also found that using the
-Waitswitch onStart-Processcaused all of the log output to be written after the install was finished. This can be fixed by using:EDIT 2: Hmm, I don’t get all of the log file when I use
-Waitand-ReadCounttogether. I put the reading of the log file back to how I originally had it. I’m not sure what to do about the speed yet.EDIT 3: I’ve updated the code to use a StreamReader instead of
Get-Content, and put the code into functions. You would then call it like: