Download and install latest Office 365 via Office Deployment Tool (ODT)

Inspired by Trond Eric Haavarstein’s evergreen PowerShell setup scripts, I created a download and install script for Office 365 Deployment Tool (ODT).


Microsoft Office 365 is the new standard in the EUC space right now. To honor this, we need a fast and reliable way to install it with our favorite deployment tools like MDT or PDQ,  for example when you rebuild your master images.

There are a few different ways to deploy Office 365, but they are all similar:

  • You need the Office 365 Click-to-run setup.exe (Office Deployment Tool (ODT))
  • You need a XML configuration file
  • You decide to deploy from a pre-build offline cache or the files are downloaded from Microsoft each and every time

And then you go: setup.exe /configure configuration.xml

Pretty straight forward you think, but non the less I had problems with this approach. And this is due to the fact, that the Office Deployment Tool itself gets updated pretty often. And this breaks your unattended deployments sooner or later, as the setup.exe stops working.

To solve this issue, I developed a PowerShell script together with Trond Eric Haavarstein, that checks the version of the Office Deployment Tool each time it’s executed. If a new version is available, it gets download and will be used immediately. If the file is already up-to-date, the download will be skipped. You will need to supply your own configuration XML file, and then you are ready to go.
Important: With the release of Office 2019, the MSI based setup was replaced by the Click2run setup trough the Office Deployment Tool (ODT), so this Blog post and script are equally valid for Office 2019, except you need a slightly different XML file. Keep this in mind.
If you don’t have a configuration XML file, there is an example file in my GitHub Repository, or check out the Office Customization Tool.

    Download and install latest Office 365 Deployment Tool (ODT)
    Download and install latest Office 365 Deployment Tool (ODT)
    Set-Location to MDT script root aka %settings%
    PS C:\> . .\install.ps1
    Downloads latest officedeploymenttool.exe
    Creates a sub-directory for each new version
    Creates the offline cache for the setup files
    Installs Office 365 to target
    Author: Marco Hofmann & Trond Eric Haavarstein
    Twitter: @xenadmin & @xenappblog
    URL: &
Download and install latest Office 365 via Office Deployment Tool (ODT)
.LINK .LINK #> function Get-ODTUri { <# .SYNOPSIS Get Download URL of latest Office 365 Deployment Tool (ODT). .NOTES Author: Bronson Magnan Twitter: @cit_bronson Modified by: Marco Hofmann Twitter: @xenadmin .LINK #> [CmdletBinding()] [OutputType([string])] param () $url = "" try { $response = Invoke-WebRequest -UseBasicParsing -Uri $url -ErrorAction SilentlyContinue } catch { Throw "Failed to connect to ODT: $url with error $_." Break } finally { $ODTUri = $response.links | Where-Object {$_.outerHTML -like "*click here to download manually*"} Write-Output $ODTUri.href } } <# PowerShell Wrapper for MDT, Standalone and Chocolatey Installation - (C)2015 Example 1: Start-Process "XenDesktopServerSetup.exe" -ArgumentList $unattendedArgs -Wait -Passthru Example 2 Powershell: Start-Process powershell.exe -ExecutionPolicy bypass -file $Destination Example 3 EXE (Always use ' '): $UnattendedArgs='/qn' (Start-Process "$PackageName.$InstallerType" $UnattendedArgs -Wait -Passthru).ExitCode Example 4 MSI (Always use " "): $UnattendedArgs = "/i $PackageName.$InstallerType ALLUSERS=1 /qn /liewa $LogApp" (Start-Process msiexec.exe -ArgumentList $UnattendedArgs -Wait -Passthru).ExitCode #> Write-Verbose "Setting Arguments" -Verbose $StartDTM = (Get-Date) $Vendor = "Microsoft" $Product = "Office 365 x32" $PackageName = "setup" $InstallerType = "exe" $LogPS = "${env:SystemRoot}" + "\Temp\$Vendor $Product $Version PS Wrapper.log" $Unattendedxml = 'RDSH.xml' $UnattendedArgs = "/configure $Unattendedxml" $UnattendedArgs2 = "/download $Unattendedxml" $URL = $(Get-ODTUri) $ProgressPreference = 'SilentlyContinue' Start-Transcript $LogPS Write-Verbose "Downloading latest version of Office 365 Deployment Tool (ODT)." -Verbose Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile .\officedeploymenttool.exe Write-Verbose "Read version number from downloaded file" -Verbose $Version = (Get-Command .\officedeploymenttool.exe).FileVersionInfo.FileVersion Write-Verbose "If downloaded ODT file is newer, create new sub-directory." -Verbose if( -Not (Test-Path -Path $Version ) ) { New-Item -ItemType directory -Path $Version Copy-item ".\$Unattendedxml" -Destination $Version -Force .\officedeploymenttool.exe /quiet /extract:.\$Version start-sleep -s 5 Write-Verbose "New folder created $Version" -Verbose } else { Write-Verbose "Version identical. Skipping folder creation." -Verbose } Set-Location $Version Write-Verbose "Downloading $Vendor $Product via ODT $Version" -Verbose if (!(Test-Path -Path .\Office\Data\ { (Start-Process "setup.exe" -ArgumentList $unattendedArgs2 -Wait -Passthru).ExitCode } else { Write-Verbose "File exists. Skipping Download." -Verbose } Write-Verbose "Starting Installation of $Vendor $Product via ODT $Version" -Verbose (Start-Process "$PackageName.$InstallerType" $UnattendedArgs -Wait -Passthru).ExitCode Write-Verbose "Customization" -Verbose Write-Verbose "Stop logging" -Verbose $EndDTM = (Get-Date) Write-Verbose "Elapsed Time: $(($EndDTM-$StartDTM).TotalSeconds) Seconds" -Verbose Write-Verbose "Elapsed Time: $(($EndDTM-$StartDTM).TotalMinutes) Minutes" -Verbose Stop-Transcript

The latest version of this script can always be found over at my GitHub repository, check it out:

Author: Marco

Marco is an IT-System administrator and IT-Consultant with 10+ years experience. He is specialized in the delivery of virtual Apps and Desktops with Citrix solutions. In 2017 he has been awarded Citrix Technology Advocate by Citrix for his community work (#CTA). His second core area is availability & performance monitoring with Zabbix, a leading open-source solution. His employer is the German IT-Company ANAXCO, which is developing a Transport Management Software (TMS) based on Microsoft Dynamics AX. More about Marco

4 thoughts on “Download and install latest Office 365 via Office Deployment Tool (ODT)”

  1. I should add i can put the url into a browser on the same VM and it downloads the ODT without issue.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.