Every IT admin will need to install the Microsoft 365 Office application at some point. Recently I have been looking for the way to automate the process of downloading the new Monthly release version of office package on to Microsoft Deployment Toolkit (MDT) server. So, the next time the machine is built, it will use the latest office application package.
The idea is to check the release version number from the vendor source and compare it against the one stored on the MDT server. If the vendor source has higher version number, it will then download the new package.
I started googling for the API link and eventually found 2 of them where you could grab the office release details. I assume this method is safer than scraping the website for version number.
- https://mrodevicemgr.officeapps.live.com/mrodevicemgrsvc/api/v2/C2RReleaseData
- https://clients.config.office.net/releases/v1.0/OfficeReleases
I tried a few Invoke-RestMethod calls and decided to use the second one to deploy it on my script.
The Assumption on the script below is that Working Directory has ODT components:
- setup.exe
- download-config.xml
- SourcePath attribute is not defined in the download-config.xml.
- If the SourcePath is defined, the $OfficeFolder should be pointing to it.
Function Get-MS365Version{
[OutputType([Version])]
Param(
[ValidateSet('Beta','MonthlyPreview','Monthly','MEC','SACT','LTSB2021','SAC','LTSB')]
[String]$Channel = 'Monthly'
)
Process{
$Uri = 'https://clients.config.office.net/releases/v1.0/OfficeReleases'
$Result = [PSObject](Invoke-RestMethod -Method Get -Uri $Uri).Where{$_.channel -eq $Channel}
Return ([Version]$Result.latestVersion)
}
}
Function Download-LatestOffice{
Param(
[Parameter()]
$WorkingDir = (Resolve-Path -Path $PSScriptRoot),
$XmlConfigFile = 'download-config.xml'
)
Begin{
$OfficeFolder = Join-Path -Path $WorkingDir -ChildPath 'Office'
$LatestVersion = Get-MS365Version
$LocalVersion = (Get-ChildItem "$OfficeFolder\Data" -Directory | Select -ExpandProperty Name) -as [Version]
}
Process{
If (Test-Path -Path "$WorkingDir\$XmlConfigFile"){
Write-Warning "Unable to locate the XML config file."
Return
}
If ($LatestVersion -gt $LocalVersion){
If (Test-Path -Path $OfficeFolder){
Write-Verbose "Removing the older version..."
Remove-Item $OfficeFolder -Recurse -Force
}
}
$Proc = @{
FilePath = Resolve-Path "$WorkingDir\Setup.exe"
ArgumentList = ("/download $XmlConfigFile")
WorkingDirectory = $WorkingDir
}
Write-Verbose "Downloading the new office release..."
Start-Process @Proc -Wait -NoNewWindow
}
}
Download-LatestOffice -Verbose
With the script above, you can now create the Scheduled Task and run it every night to check if there is a new monthly release of the office application package.
My favourite Scheduled Task Action Parameters:
- Program/Script: PowerShell.exe
- Add Argument: -ExecutionPolicy ByPass -WindowStyle Hidden -File .\Get-LatestOffice.ps1
- Start in: D:\DeploymentShare\Application\Microsoft Office365
You could use the same script to update your office package on the network share, if you use group policy to deploy the office app.
For Further Info on Microsoft 365 Office Deployment: