Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Downloads and installs the latest available Microsoft product specified directly on the client. This avoids having to manually download and store an up-to-date installer on a distribution server every month.
#!/bin/zsh
:<<'ABOUT_THIS_SCRIPT'
-----------------------------------------------------------------------
Written by:William Smith
Professional Services Engineer
Jamf
bill@talkingmoose.net
https://gist.github.com/talkingmoose/a16ca849416ce5ce89316bacd75fc91a
Originally posted: November 19, 2017
Updated: January 20, 2020
Purpose: Downloads and installs the latest available Microsoft
product specified directly on the client. This avoids having to
manually download and store an up-to-date installer on a
distribution server every month.
Instructions: Update the linkID value to one of the corresponding
Microsoft products in the list and optionally update the sha256Checksum
value with a known SHA 256 string. Run the script with elevated
privileges. If using Jamf Pro, consider replacing the linkID and
sha256Checksum values with "$4" and "$5", entering the ID as script
parameters in a policy.
Except where otherwise noted, this work is licensed under
http://creativecommons.org/licenses/by/4.0/
"You say goodbye and I say exit 0."
-----------------------------------------------------------------------
ABOUT_THIS_SCRIPT
# enter the Microsoft fwlink (permalink) product ID
# or leave blank if using a $4 script parameter with Jamf Pro
linkID="" # e.g. "525133" for Office 2019
# 525133 - Office 2019 for Mac SKUless download (aka Office 365)
# 2009112 - Office 2019 for Mac BusinessPro SKUless download (aka Office 365 with Teams)
# 871743 - Office 2016 for Mac SKUless download
# 830196 - AutoUpdate download
# 2069148 - Edge (Consumer Stable)
# 2069439 - Edge (Consumer Beta)
# 2069340 - Edge (Consumer Dev)
# 2069147 - Edge (Consumer Canary)
# 2093438 - Edge (Enterprise Stable)
# 2093294 - Edge (Enterprise Beta)
# 2093292 - Edge (Enterprise Dev)
# 525135 - Excel 2019 SKUless download
# 871750 - Excel 2016 SKUless download
# 869655 - InTune Company Portal download
# 823060 - OneDrive download
# 820886 - OneNote download
# 525137 - Outlook 2019 SKUless download
# 871753 - Outlook 2016 SKUless download
# 525136 - PowerPoint 2019 SKUless download
# 871751 - PowerPoint 2016 SKUless download
# 868963 - Remote Desktop
# 800050 - SharePoint Plugin download
# 832978 - Skype for Business download
# 869428 - Teams
# 525134 - Word 2019 SKUless download
# 871748 - Word 2016 SKUless download
# enter the SHA 256 checksum for the download file
# download the package and run '/usr/bin/shasum -a 256 /path/to/file.pkg'
# this will change with each version
# leave blank to to skip the checksum verification (less secure) or if using a $5 script parameter with Jamf Pro
sha256Checksum="" # e.g. "67b1e8e036c575782b1c9188dd48fa94d9eabcb81947c8632fd4acac7b01644b"
if [ "$4" != "" ] && [ "$linkID" = "" ]
then
linkID=$4
fi
if [ "$5" != "" ] && [ "$sha256Checksum" = "" ]
then
sha256Checksum=$5
fi
# this is the full fwlink URL
url="https://go.microsoft.com/fwlink/?linkid=$linkID"
# create temporary working directory
echo "Creating working directory '$tempDirectory'"
workDirectory=$( /usr/bin/basename $0 )
tempDirectory=$( /usr/bin/mktemp -d "/private/tmp/$workDirectory.XXXXXX" )
# change directory to temporary working directory
echo "Changing directory to working directory '$tempDirectory'"
cd "$tempDirectory"
# download the installer package and name it for the linkID
echo "Downloading package $linkID.pkg"
/usr/bin/curl --location --silent "$url" -o "$linkID.pkg"
# checksum the download
downloadChecksum=$( /usr/bin/shasum -a 256 "$tempDirectory/$linkID.pkg" | /usr/bin/awk '{ print $1 }' )
echo "Checksum for downloaded package: $downloadChecksum"
# install the package if checksum validates
if [ "$sha256Checksum" = "$downloadChecksum" ] || [ "$sha256Checksum" = "" ]; then
echo "Checksum verified. Installing package $linkID.pkg"
/usr/sbin/installer -pkg "$linkID.pkg" -target /
exitCode=0
else
echo "Checksum failed. Recalculate the SHA 256 checksum and try again. Or download may not be valid."
exitCode=1
fi
# remove the temporary working directory when done
/bin/rm -Rf "$tempDirectory"
echo "Deleting working directory '$tempDirectory' and its contents"
exit $exitCode
#!/bin/zsh
:<<'ABOUT_THIS_SCRIPT'
-----------------------------------------------------------------------
Written by:William Smith
Professional Services Engineer
Jamf
bill@talkingmoose.net
https://gist.github.com/talkingmoose/a16ca849416ce5ce89316bacd75fc91a
Originally posted: November 19, 2017
Updated: January 20, 2020
Purpose: Downloads and installs the latest available Microsoft
product specified directly on the client. This avoids having to
manually download and store an up-to-date installer on a
distribution server every month.
Instructions: Update the linkID value to one of the corresponding
Microsoft products in the list and optionally update the sha256Checksum
value with a known SHA 256 string. Run the script with elevated
privileges. If using Jamf Pro, consider replacing the linkID and
sha256Checksum values with "$4" and "$5", entering the ID as script
parameters in a policy.
Except where otherwise noted, this work is licensed under
http://creativecommons.org/licenses/by/4.0/
"You say goodbye and I say exit 0."
-----------------------------------------------------------------------
ABOUT_THIS_SCRIPT
# enter the Microsoft fwlink (permalink) product ID
# or leave blank if using a $4 script parameter with Jamf Pro
linkID="" # e.g. "525133" for Office 2019
# 525133 - Office 2019 for Mac SKUless download (aka Office 365)
# 2009112 - Office 2019 for Mac BusinessPro SKUless download (aka Office 365 with Teams)
# 871743 - Office 2016 for Mac SKUless download
# 830196 - AutoUpdate download
# 2069148 - Edge (Consumer Stable)
# 2069439 - Edge (Consumer Beta)
# 2069340 - Edge (Consumer Dev)
# 2069147 - Edge (Consumer Canary)
# 2093438 - Edge (Enterprise Stable)
# 2093294 - Edge (Enterprise Beta)
# 2093292 - Edge (Enterprise Dev)
# 525135 - Excel 2019 SKUless download
# 871750 - Excel 2016 SKUless download
# 869655 - InTune Company Portal download
# 823060 - OneDrive download
# 820886 - OneNote download
# 525137 - Outlook 2019 SKUless download
# 871753 - Outlook 2016 SKUless download
# 525136 - PowerPoint 2019 SKUless download
# 871751 - PowerPoint 2016 SKUless download
# 868963 - Remote Desktop
# 800050 - SharePoint Plugin download
# 832978 - Skype for Business download
# 869428 - Teams
# 525134 - Word 2019 SKUless download
# 871748 - Word 2016 SKUless download
# enter the SHA 256 checksum for the download file
# download the package and run '/usr/bin/shasum -a 256 /path/to/file.pkg'
# this will change with each version
# leave blank to to skip the checksum verification (less secure) or if using a $5 script parameter with Jamf Pro
sha256Checksum="" # e.g. "67b1e8e036c575782b1c9188dd48fa94d9eabcb81947c8632fd4acac7b01644b"
if [ "$4" != "" ] && [ "$linkID" = "" ]
then
linkID=$4
fi
if [ "$5" != "" ] && [ "$sha256Checksum" = "" ]
then
sha256Checksum=$5
fi
# this is the full fwlink URL
url="https://go.microsoft.com/fwlink/?linkid=$linkID"
# create temporary working directory
echo "Creating working directory '$tempDirectory'"
workDirectory=$( /usr/bin/basename $0 )
tempDirectory=$( /usr/bin/mktemp -d "/private/tmp/$workDirectory.XXXXXX" )
# change directory to temporary working directory
echo "Changing directory to working directory '$tempDirectory'"
cd "$tempDirectory"
# download the installer package and name it for the linkID
echo "Downloading package $linkID.pkg"
/usr/bin/curl --location --silent "$url" -o "$linkID.pkg"
# checksum the download
downloadChecksum=$( /usr/bin/shasum -a 256 "$tempDirectory/$linkID.pkg" | /usr/bin/awk '{ print $1 }' )
echo "Checksum for downloaded package: $downloadChecksum"
# install the package if checksum validates
if [ "$sha256Checksum" = "$downloadChecksum" ] || [ "$sha256Checksum" = "" ]; then
echo "Checksum verified. Installing package $linkID.pkg"
/usr/sbin/installer -pkg "$linkID.pkg" -target /
exitCode=0
else
echo "Checksum failed. Recalculate the SHA 256 checksum and try again. Or download may not be valid."
exitCode=1
fi
# remove the temporary working directory when done
/bin/rm -Rf "$tempDirectory"
echo "Deleting working directory '$tempDirectory' and its contents"
exit $exitCode
@malroy
Copy link

malroy commented May 17, 2019

HI there,
maybe can add Teams
869428 - Teams download

@thisisjaysnyder
Copy link

thisisjaysnyder commented Aug 28, 2019

I was able to use your script to push out the office install from Maas360 (thank you!). Is there a way to have it do a silent install so that the users do not have to click through the configuration?

@talkingmoose
Copy link
Author

talkingmoose commented Aug 30, 2019

The install should already be silent. However, you're referring to Office 365 activation, you can't silently activate for a user, but you can definitely minimize the amount of user interaction needed. While I wrote this for Jamf Pro, the configuration profiles will work with any MDM.

Help users activate Microsoft Office 365 and configure Outlook in one click

@thisisjaysnyder
Copy link

thisisjaysnyder commented Aug 30, 2019

@vermaajju65
Copy link

vermaajju65 commented Jul 26, 2022

how to find the Microsoft teams Microsoft fwlink ?

@talkingmoose
Copy link
Author

talkingmoose commented Jul 26, 2022

@vermaajju65 Line 63?

@vermaajju65
Copy link

vermaajju65 commented Jul 26, 2022

with this ID installing the older version teams. where did you find these Microsoft fwlink ?

@talkingmoose
Copy link
Author

talkingmoose commented Jul 26, 2022

It's the same one available at this page:
https://www.microsoft.com/en-us/microsoft-teams/download-app

You'll see the fwlink in the download link of the Download button.

@natkoo
Copy link

natkoo commented Oct 11, 2022

Getting this error in Jamf on 2093438 - Edge (Enterprise Stable)

Script result: Creating working directory ''
Changing directory to working directory '/private/tmp/Download latest Office and Install.pi7zOI'
Downloading package 2093438.pkg
Checksum for downloaded package: c782d94ddeaf3945795a0afbf0f160064c6242d450c5c7ce914ccead65f6cba5
Checksum verified. Installing package 2093438.pkg
installer: Error - the package path specified was invalid: '2093438.pkg'.
Deleting working directory '/private/tmp/Download latest Office and Install.pi7zOI' and its contents

Any ideas why?

@DeployNull
Copy link

DeployNull commented Oct 11, 2022

@natkoo linkID 2093438 currently seems to redirect to https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/095d0740-fddd-45d6-8e13-0b2488a3510f/edge_arm_stable_105.0.1343.50_Tencent.apk which isn't a package format for macOS devices and thus it cannot be installed.

You can determine the redirection url by yourself with help of /usr/bin/curl --head "https://go.microsoft.com/fwlink/?linkid=2093438" and viewing the value of the Location key or typing this one-liner:
/usr/bin/curl -w "%{redirect_url}\n" -o /dev/null -s "https://go.microsoft.com/fwlink/?linkid=2093438"

Which will output the url to this .apk file.

Why linkID 2093438 have been changed to this redirection url, I don't know.

But there is a new "Edge Stable Channel Installer" linkID listed on page https://macadmins.software:
https://go.microsoft.com/fwlink/?linkid=2093504

That linkID seem to redirect to the same installer url that is being listed on the download page for Microsoft Edge for Business:
https://www.microsoft.com/en-us/edge/business/download (Click on macOS - Download and copy the url listed on the Accept and Download button, and it should be the same).

So I would suggest switching to using linkID 2093504.

Cheers!

@natkoo
Copy link

natkoo commented Oct 12, 2022

@natkoo linkID 2093438 currently seems to redirect to https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/095d0740-fddd-45d6-8e13-0b2488a3510f/edge_arm_stable_105.0.1343.50_Tencent.apk which isn't a package format for macOS devices and thus it cannot be installed.

You can determine the redirection url by yourself with help of /usr/bin/curl --head "https://go.microsoft.com/fwlink/?linkid=2093438" and viewing the value of the Location key or typing this one-liner: /usr/bin/curl -w "%{redirect_url}\n" -o /dev/null -s "https://go.microsoft.com/fwlink/?linkid=2093438"

Which will output the url to this .apk file.

Why linkID 2093438 have been changed to this redirection url, I don't know.

But there is a new "Edge Stable Channel Installer" linkID listed on page https://macadmins.software: https://go.microsoft.com/fwlink/?linkid=2093504

That linkID seem to redirect to the same installer url that is being listed on the download page for Microsoft Edge for Business: https://www.microsoft.com/en-us/edge/business/download (Click on macOS - Download and copy the url listed on the Accept and Download button, and it should be the same).

So I would suggest switching to using linkID 2093504.

Cheers!

Ok i see! Thank you so much, works now :)

@mani2care
Copy link

mani2care commented Oct 19, 2022

Is there any option to use that swiftDialog to do this with that transparent download and install.

@talkingmoose
Copy link
Author

talkingmoose commented Oct 19, 2022

@mani2care Anything beyond this script would be for you to develop. You're free to repurpose it for your own needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment