Install a specific Office 365 version on the fly using the ODT

From time to time our customer support needs to install a specific version of office 365 to match what the customer has, so they can troubleshoot an issue.
Anyway this code below allows us to automate the process, so the bigfix operator can send out the version the user has requested.
This same process can be used with office 2019
Thank you to Jason who helped me with a previous office 365 channel project, which made this project possible.
In my code I uninstall the previous version of office, but during my tests you don’t need to uninstall previous versions, the office install will downgrade it, but just to be safe I do a uninstall of office, before I install the specific version.

action parameter query "Channel" with description "Enter the Version to be Installed.%0d%0aAccepted values: example; 16.0.15128.20280 " with default "<Enter the Version Name>"

parameter "SourceFolder"="C:\Users\Public\xyz\Office" as string & "\Office365AdvPatch"}"

if {exists folder (parameter "SourceFolder")}
	folder delete "{parameter "SourceFolder"}"
endif

folder create "{parameter "SourceFolder"}"
folder create "C:\Users\Public\xyz\Office"

//downloading ODT
delete __createfile
wait curl.exe -L "https://www.microsoft.com/en-us/download/confirmation.aspx?id=49117" --output "C:\Users\Public\xyz\Office\test.html"
parameter "DownloadInfoHTML"="{(it, following text of last "/" of it | it) of node values of attributes "href" of xpaths ("xmlns:mscom='http://schemas.microsoft.com/CMSvNext'  xmlns:xhtml='http://www.w3.org/1999/xhtml'", "//xhtml:a[@class='mscom-link failoverLink']" ) of xml documents of files "C:\Users\Public\xyz\Office\test.html"}"
parameter "DownloadURL"="{tuple string item 0 of parameter "DownloadInfoHTML"}"
parameter "DownloadFile"="{tuple string item 1 of parameter "DownloadInfoHTML"}"
wait curl -L "{parameter "DownloadURL"}" --output "C:\Users\Public\xyz\Office\{parameter "DownloadFile"}"

//Extracting ODT
waithidden C:\Users\Public\xyz\Office\{parameter "DownloadFile"} /quiet /extract:"C:\Users\Public\xyz\Office"

// Uninstall office
delete __appendfile
appendfile <Configuration>
appendfile     <Display Level="none" CompletionNotice="no" SuppressModal="yes" AcceptEula="yes" />
appendfile     <Logging Level="Standard" Path="%temp%" />
appendfile <Remove>
appendfile <Product ID="O365ProPlusRetail" >
appendfile <Remove>
appendfile </Configuration>
move __appendfile "C:\Users\Public\xyz\Office\uninstall.xml"

delete __createfile
delete run.bat
createfile until _end_
@ECHO OFF
cd\Users\Public\xyz\Office
C:\Users\Public\xyz\setup.exe /configure C:\Users\Public\xyz\uninstall.xml
_end_
move __createfile run.bat
move run.bat "C:\Users\Public\xyz\Office\run.bat"
waithidden "C:\Users\Public\xyz\Office\run.bat"


delete C:\Users\Public\xyz\configuration-Office365-x64.xml
delete C:\Users\Public\xyz\configuration-Office365-x86.xml
delete C:\Users\Public\xyz\configuration-Office2021Enterprise.xml
delete C:\Users\Public\xyz\configuration-Office2019Enterprise.xml
delete C:\Users\Public\xyz\{parameter "DownloadFile"}

//Xml attributes
if{x32 of operating system}
parameter "Edition" = "32"
else
parameter "Edition" = "64"
endif


delete __appendfile
appendfile <Configuration>
appendfile   <Add OfficeClientEdition="{parameter "Edition"}" Version="{parameter "Channel"}">
appendfile     <Product ID="O365ProPlusRetail" >
appendfile       <Language ID="en-us" />
appendfile     </Product>
appendfile   </Add>
appendfile <Display Level="None" AcceptEULA="TRUE" />
appendfile <Property Name="AUTOACTIVATE" Value="1" />
appendfile <Updates Enabled="false" Version="{parameter "Channel"}" />
appendfile </Configuration>

move __appendfile "C:\Users\Public\xyz\Office\configuration.xml"

delete __createfile
delete run.bat
createfile until _end_
@ECHO OFF
cd\Users\Public\xyz\Office
C:\Users\Public\xyz\Office\setup.exe /download C:\Users\Public\xyz\Office\configuration.xml
C:\Users\Public\xyz\Office\setup.exe /configure C:\Users\Public\xyz\Office\configuration.xml
_end_

delete "C:\Users\Public\xyz\Office\run.bat"
move __createfile run.bat
move run.bat "C:\Users\Public\xyz\Office\run.bat"
waithidden "C:\Users\Public\xyz\Office\run.bat"
folder delete "C:\Users\Public\xyz\Office"


pause while {not exists keys whose (value "DisplayName" of it as string as lowercase contains "365") of key "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of native registry}

// After installation Cleanup
folder delete "{parameter "SourceFolder"}"
1 Like

I had to make a slight adjustment to the code, below is the updated code.
I found that you have to include the ODT line <Updates Enabled=“false” Channel="{parameter “Channel”}" /> and it has to include the matching Channel for the Version, or else you would get random versions for some channels, if you tried using the word version instead as I did in my first attempt at the fixlet.
So to make this work, I have to prompt the bigfix operator for the Channel, Version and Bitness.

action parameter query "Channel" with description "Enter the Channel the required version is in.%0d%0aAccepted values: Current, SemiAnnual, SemiAnnualPreview, MonthlyEnterprise" with default "<Enter the Channel Name>"

action parameter query "Version" with description "Enter the Version to be Installed.%0d%0aAccepted values: example; 16.0.15128.20280 " with default "<Enter the Version Name>"

action parameter query "Bitness" with description "Enter the Bitness to be Installed.%0d%0aAccepted values: 32 or 64 " with default "<Enter the Version Name>"

parameter "SourceFolder"="C:\Users\Public\xyz\Office" as string & "\Office365AdvPatch"}"

if {exists folder (parameter "SourceFolder")}
	folder delete "{parameter "SourceFolder"}"
endif

folder create "{parameter "SourceFolder"}"
folder create "C:\Users\Public\xyz\Office"

//downloading ODT
delete __createfile
wait curl.exe -L "https://www.microsoft.com/en-us/download/confirmation.aspx?id=49117" --output "C:\Users\Public\xyz\Office\test.html"
parameter "DownloadInfoHTML"="{(it, following text of last "/" of it | it) of node values of attributes "href" of xpaths ("xmlns:mscom='http://schemas.microsoft.com/CMSvNext'  xmlns:xhtml='http://www.w3.org/1999/xhtml'", "//xhtml:a[@class='mscom-link failoverLink']" ) of xml documents of files "C:\Users\Public\xyz\Office\test.html"}"
parameter "DownloadURL"="{tuple string item 0 of parameter "DownloadInfoHTML"}"
parameter "DownloadFile"="{tuple string item 1 of parameter "DownloadInfoHTML"}"
wait curl -L "{parameter "DownloadURL"}" --output "C:\Users\Public\xyz\Office\{parameter "DownloadFile"}"

//Extracting ODT
waithidden C:\Users\Public\xyz\Office\{parameter "DownloadFile"} /quiet /extract:"C:\Users\Public\xyz\Office"

// Uninstall office
delete __appendfile
appendfile <Configuration>
appendfile     <Display Level="none" CompletionNotice="no" SuppressModal="yes" AcceptEula="yes" />
appendfile     <Logging Level="Standard" Path="%temp%" />
appendfile <Remove>
appendfile <Product ID="O365ProPlusRetail" >
appendfile <Remove>
appendfile </Configuration>
move __appendfile "C:\Users\Public\xyz\Office\uninstall.xml"

delete __createfile
delete run.bat
createfile until _end_
@ECHO OFF
cd\Users\Public\xyz\Office
C:\Users\Public\xyz\setup.exe /configure C:\Users\Public\xyz\uninstall.xml
_end_
move __createfile run.bat
move run.bat "C:\Users\Public\xyz\Office\run.bat"
waithidden "C:\Users\Public\xyz\Office\run.bat"

delete C:\Users\Public\xyz\configuration-Office365-x64.xml
delete C:\Users\Public\xyz\configuration-Office365-x86.xml
delete C:\Users\Public\xyzd\configuration-Office2021Enterprise.xml
delete C:\Users\Public\xyz\configuration-Office2019Enterprise.xml
delete C:\Users\Public\xyz\{parameter "DownloadFile"}

//Xml attributes
delete __appendfile
appendfile <Configuration>
appendfile   <Add OfficeClientEdition="{parameter "Bitness"}" Version="{parameter "Version"}">
appendfile     <Product ID="O365ProPlusRetail" >
appendfile       <Language ID="en-us" />
appendfile     </Product>
appendfile   </Add>
appendfile <Display Level="None" AcceptEULA="TRUE" />
appendfile <Property Name="AUTOACTIVATE" Value="1" />
appendfile <Updates Enabled="false" Channel="{parameter "Channel"}" />
appendfile </Configuration>

move __appendfile "C:\Users\Public\xyz\Office\configuration.xml"

delete __createfile
delete run.bat
createfile until _end_
@ECHO OFF
cd\Users\Public\xyz\Office
C:\Users\Public\xyz\Office\setup.exe /download C:\Users\Public\xyz\Office\configuration.xml
C:\Users\Public\xyz\Office\setup.exe /configure C:\Users\Public\xyz\Office\configuration.xml
_end_

delete "C:\Users\Public\xyz\Office\run.bat"
move __createfile run.bat
move run.bat "C:\Users\Public\xyz\Office\run.bat"
waithidden "C:\Users\Public\xyz\Office\run.bat"

pause while {not exists keys whose (value "DisplayName" of it as string as lowercase contains "365") of key "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of native registry}

// After installation Cleanup
folder delete "{parameter "SourceFolder"}"
folder delete "C:\Users\Public\xyz\Office"

Tip on posting Code formatting to the Forum (Discourse is trying to parse your XML tags as HTML).
I’ll fix the formatting on your post above, thanks for sharing!

thank you for the tip, sorry my mistake.