I modified mine a bit and it works.
I noticed, if you have MSOffice 2021 installed after remove the 2019, and schedule to run the policy frequently, then anytime the policy runs, it will automatically close the app w/t saving work while the end user having it open. I would think about we should have the validation check: When run the policy, it would check if the client machine already has MSOffice 2021 installed, then skip it. If not, then install…
I don’t have any source to come up with the script, but found in the root dir, there’s a txt file that I can use for the validation. Just want to share, but if you have any better script, pls share as well.
worklet
Remediation Code:
Start-Transcript -Verbose -Path "c:\MSOffice2021\msoffice2021.log"
Copy-Item ConfigurationLocal2021.bat -Destination "c:\MSOffice2021\ConfigurationLocal2021.bat" -Verbose
Copy-Item ConfigurationLocal2021.xml -Destination "c:\MSOffice2021\ConfigurationLocal2021.xml" -Verbose
Copy-Item setup.exe -Destination "c:\MSOffice2021\setup.exe" -Verbose
$checkfile = "C:\Program Files\Microsoft Office\root\Office16\1033\ClientLangPack2021_eula.txt"
if (Get-Item $checkfile -Verbose) {
Write-Output "Microsoft Office 2021 is already installed. Skipping..."
Write-Output "Exit Code: $LASTEXITCODE"
exit
} else {
Write-Output "Microsoft Office 2021 not installed, installing..."
WindowStyle Hidden -Wait -Passthru).ExitCode
Start-Process -FilePath "C:\MSOffice2021\ConfigurationLocal2021.bat" -WindowStyle Hidden -Wait -Passthru -Verbose