$ErrorActionPreference = 'Stop'
$url = 'https://download.documentfoundation.org/libreoffice/stable/25.8.6/win/x86_64/LibreOffice_25.8.6_Win_x86-64.msi'
$msi = 'C:\Windows\Temp\lo.msi'
Write-Host "Downloading LibreOffice 25.8.6..."
Invoke-WebRequest -Uri $url -OutFile $msi -UseBasicParsing
Write-Host ("Downloaded {0:N1} MB" -f ((Get-Item $msi).Length / 1MB))
Write-Host "Installing silently (4-6 min)..."
$p = Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart', 'ADDLOCAL=ALL', 'CREATEDESKTOPLINK=0' -Wait -PassThru
Write-Host "Exit code: $($p.ExitCode)"
Remove-Item $msi -ErrorAction SilentlyContinue
if (Test-Path 'C:\Program Files\LibreOffice\program\soffice.exe') {
    Write-Host "OK: soffice.exe installed"
    & 'C:\Program Files\LibreOffice\program\soffice.exe' --version
} else {
    Write-Error "soffice.exe NOT found after install"
}
