Worklet: Install Microsoft Office on Windows

Hi all, I thought I’d upload the worklet I am using to install Microsoft Office (I know, there’s probably other and better ways to do this but this method works for us.)

I downloaded the Office Deployment Tool via https://www.microsoft.com/en-us/download/details.aspx?id=49117, extracted it and uploaded the setup executable to my Worklet and configured the XML to fit my needs - you can also configure that here https://config.office.com/ - and uploaded it to my Worklet. You may need to rename them in the worklet so they have your correct the filenames.

The evaluation first checks whether the Microsoft Office directory exists in Program Files, if found, it then uses the O365 installer. The remediation then logs everything in verbose to a msoffice.log file, copies the uploaded files to a temp directory, checks whether the path exists, if so, writes the output and skips the install, otherwise it installs it.

Evaluation:

if (Test-Path -Path "C:\Program Files\Microsoft Office") 
{
	exit 0
} 
else 
{ 
	Exit 1 
}

Remediation

Start-Transcript -Verbose -Path "c:\temp\msoffice.log"

Copy-Item configurationx64.xml -Destination "c:\temp\configurationx64.xml" -Verbose
Copy-Item msoffice.exe -Destination "c:\temp\msoffice.exe" -Verbose

$path = "C:\Program Files\Microsoft Office"

# Check if Microsoft Office 365 is installed
if (Test-Path $path -Verbose) {
    Write-Output "Microsoft Office 365 is already installed. Skipping..."
    Write-Output "Exit Code: $LASTEXITCODE"
    exit
}
else {
    Write-Output "Microsoft Office 365 not installed, installing..."
    Start-Process -FilePath "c:\temp\msoffice.exe" -argumentlist '/configure c:\temp\configurationx64.xml' -Verbose
    Write-Output "Microsoft Office 365 has been installed."
}

Stop-Transcript

Hope this helps someone.

thank you for this, worked like a charm.

2 Likes