Script Help for Deploying Office 2016 w/ Prefs

TomDay
Release Candidate Programs Tester

I've been building our Office 2016 deployment, using all info scraped from JamfNation and it's working really well for deploying the 2016 install, removing 2008, setting the dock, but I'm having problems in the script with deploying preferences. I want to set the username, disable cloud signin, disable first run and enable Auto Updates with Download and install. The piece of preferences deployment that is working is the disabling of first run, no other preferences are being set properly. Would some scripting gurus kindly offer some advice?

#!/bin/sh
#Create the choices file and apply to the installer
cat  <<'EOF' >> /private/tmp/Office2016Install/choices.xml
<array>
    <string>com.microsoft.onenote.mac</string>
    <string>com.microsoft.outlook</string>
</array>

EOF

/usr/sbin/installer -pkg /private/tmp/Office2016Install/Microsoft_Office_2016_15.37.17081500_Volume_Installer.pkg -applyChoiceChangesXML /private/tmp/Office2016Install/choices.xml -target /

#Remove Office 2008
#Kill any running Office 2008 apps
killall 'Microsoft Word'
killall 'Microsoft Excel'
killall 'Microsoft Powerpoint'

echo Removing Office 2008
sleep 5
echo Removing Office from Applications
sudo rm -rf /Applications/Microsoft Office 2008
sleep 5
echo Removing Office Library files
sudo rm -rf /Library/com.microsoft.*
sudo rm -rf ~/Library/com.microsoft.*
sudo rm -rf /Library/Microsoft/Office 2008
sudo rm -rf ~/Library/Microsoft/Office 2008
sudo rm -rf /Library/LaunchDaemons/com.microsoft.*
sudo rm -rf /Library/PrivilegedHelperTools/com.microsoft.*
sudo rm -rf /Library/Application Support/Microsoft
sudo rm -rf ~/Library/Application Support/Microsoft
echo
echo
sleep 5
echo Cleaning up some files
echo
sudo rm -rf /Library/Receipts/Office2008_en*
sudo rm -rf /private/var/db/receipts/com.microsoft.*
sleep 5
echo Removing user Microsoft data
sudo rm -rf ~/Documents/Microsoft User Data
sleep 5
echo Removing startup items
sudo rm -rf ~/Library/Preferences/Microsoft/Office 2008/Microsoft Office 2008 Settings.plist
sleep 5

#Set autoupdate to manual
#defaults write com.microsoft.autoupdate2 HowToCheck Manual

#Set autoupdate to Download and Install
defaults write com.microsoft.autoupdate2 HowToCheck AutomaticDownload

#Set autoupdate to Download and Install (Updated Location for future)
#defaults write /Library/Preferences/com.microsoft.autoupdate2 HowToCheck AutomaticDownload

#Set default save location to On My Mac instead of Online Locations
defaults write com.microsoft.office DefaultsToLocalOpenSave -bool true

#Disable Signin Services
defaults write com.microsoft.Excel SignInOptions 4
defaults write com.microsoft.Powerpoint SignInOptions 4
defaults write com.microsoft.Word SignInOptions 4

#Turns off the FirstRunScreen for each application.
/usr/bin/defaults write /Library/Preferences/com.microsoft.PowerPoint kSubUIAppCompletedFirstRunSetup1507 -bool true
/usr/bin/defaults write /Library/Preferences/com.microsoft.Excel kSubUIAppCompletedFirstRunSetup1507 -bool true
/usr/bin/defaults write /Library/Preferences/com.microsoft.Word kSubUIAppCompletedFirstRunSetup1507 -bool true


#PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/libexec
export PATH

FullScriptName=$(basename "$0") # Variable used to store the file name of this script

DsclSearchPath="/Local/Default" # Variable used to store the search path used by the dscl command.

#Get the username of the person currently running the script.
username=$(id -un)

echo "$FullScriptName -- Personalizing Office 2016 for $username"

#Lookup the user's name from the local directory
firstname=$(dscl "$DsclSearchPath" -read /Users/$username RealName | tr -d '
' | awk '{print $2}')
lastname=$(dscl "$DsclSearchPath" -read /Users/$username RealName | tr -d '
' | awk '{print $3}')

#Get the first letter for the initial
firstInitial=${firstname:0:1}

#Get the first letter for the initial
lastInitial=${lastname:0:1}

#Concatenate the initials together into one variable.
UserInitials="$(echo $firstInitial$lastInitial)"

#Concatenate the full name together into one variable.
UserFullName="$(echo $firstname $lastname)"

#Remove any leading or trailing whitepace
UserFullName="$(echo -e "${UserFullName}" | sed -e 's/^[[:space:]]//' -e 's/[[:space:]]$//')"
UserInitials="$(echo -e "${UserInitials}" | sed -e 's/^[[:space:]]//' -e 's/[[:space:]]$//')"

/usr/bin/defaults write "/Users/$username/Library/Group Containers/UBF8T346G9.Office/MeContact.plist" Name "$UserFullName"

/usr/bin/defaults write "/Users/$username/Library/Group Containers/UBF8T346G9.Office/MeContact.plist" Initials "$UserInitials"

echo "$FullScriptName -- Completed personalizing Office 2016 for $username"

# Dock Icons change - for current user and all existing users on this computer
echo "Add/Replace Office dock items"

/usr/local/bin/dockutil --add '/Applications/Microsoft Word.app' --replacing 'Microsoft Word' --allhomes
/bin/sleep 5
/usr/local/bin/dockutil --add '/Applications/Microsoft Excel.app' --replacing 'Microsoft Excel' --allhomes
/bin/sleep 5
/usr/local/bin/dockutil --add '/Applications/Microsoft PowerPoint.app' --replacing 'Microsoft PowerPoint' --allhomes
/bin/sleep 5

echo "Refresh Dock"
killall cfprefsd
killall Dock

#Quit the script without errors.

exit 0
1 ACCEPTED SOLUTION

talkingmoose
Moderator
Moderator

@TomDay, I have some plist and script examples for managing Office 2016 applications here. The scripts are just an alternative way of doing things if you can't use profiles.

https://github.com/talkingmoose/Microsoft-Office-2016-for-Mac-Management

Let me know if you have any questions.

To date, this is the most comprehensive list of keys/values for creating configuration profiles I've seen.

https://goo.gl/UC04oZ

View solution in original post

12 REPLIES 12

Asnyder
Contributor III

Have you tried running the installer after removing all of the office 2008 files instead of before? I'm not sure if it makes much of a difference but you're installing office 16 and then searching for office files and removing them. I would change the order to remove all the old files first and then run the installer for 16, and next write the preferences. Just in case the plist files are being removed after installing office.

Edit: You're running

sudo rm -rf /Library/com.microsoft.*
sudo rm -rf ~/Library/com.microsoft.*

after installing which I think is blowing away the plists named similarly

talkingmoose
Moderator
Moderator

@TomDay, how are you deploying your script? User settings need to run as the current user. If you're deploying through Jamf, however, the script will run as root. Your current script seems to be doing a mix of both, which won't work.

Have you considered (or are you familiar with) using configuration profiles to manage these Office 2016 preferences? Profiles can manage across multiple users on a device. I strongly recommend them over a script. I would keep the script to remove the old version of Office and use profiles to manage preferences for the new version of Office.

TomDay
Release Candidate Programs Tester

@talkingmoose TYVM, deploying via jamf policy. Lesson learned here about root, appreciate your input. When I broke the script out for some troubleshooting, I saw a reference in the results to "root".

We do use some config profiles so I can familiar with them. I'll separate the script and pull the preference pieces out. Have a favorite site or github that has the profiles I can download?

TomDay
Release Candidate Programs Tester

@Asnyder makes sense, thanks for pointing that out, I'll remove 08 first!

talkingmoose
Moderator
Moderator

@TomDay, I have some plist and script examples for managing Office 2016 applications here. The scripts are just an alternative way of doing things if you can't use profiles.

https://github.com/talkingmoose/Microsoft-Office-2016-for-Mac-Management

Let me know if you have any questions.

To date, this is the most comprehensive list of keys/values for creating configuration profiles I've seen.

https://goo.gl/UC04oZ

TomDay
Release Candidate Programs Tester

@talkingmoose These are awesome! As I work with the Autoupdate piece, I notice the plists are named the same "com.microsoft.autoupdate2.plist". Does that matter as I create them in TextWrangler and upload to Jamf or do I need to rename them? Also, in your notes, "Ensure the target domain is com.microsoft.autoupdate2.", could elaborate?

For autoupdate, I am going to create a plist to set to download and install and then another plist to set the frequency.

-Tom

talkingmoose
Moderator
Moderator

@TomDay, the name definitely matters.

Configuration Profiles are all about managing plists. Each app has its own plist, which is named for the domain of the app. For example, the domain for Microsoft AutoUpdate is com.microsoft.autoupdate2. Its preference file is named com.microsoft.autoupdate2.plist. You'll find this file here: ~/Library/Preferences/com.microsoft.autoupdate2.plist. If you don't specify the correct domain name in the Configuration Profile, it won't work.

Jamf takes the plist name and simply strips off the file extension to auto-complete the Preference Domain field in the Custom Settings payload when you upload the plist file to your configuration profile. Name your plist files whatever you like. You may need to adjust the Preference Domain field to use the correct domain name. But if you name your plist files the same as the plist file you're managing, everything just falls into place.

Keep in mind, you only need to upload one plist file per app. You can include multiple key/value pairs in a single plist file.

TomDay
Release Candidate Programs Tester

@talkingmoose Ah that clears it up. I think I'll keep the plists separate right now until I have a firm handle on creation and deployment of thee pieces, then I'll learn how to add multiple dictionaries in one file. Trying to get this pushed out before I head to JNUC Monday! Getting some strange errors when pushing the profile out "unable to decrypt encrypted profile".
7b31bbb0a2f04535820fa7e813912278

talkingmoose
Moderator
Moderator

@TomDay, be sure the Preference Domain is named com.microsoft.autoupdate2. Do not include the .plist file extension.

mahughe
Contributor

config profiles are definitely the way to go here thanks to this same advice from @talkingmoose not long ago..

TomDay
Release Candidate Programs Tester

@talkingmoose ah the little errors, thanks for pointing that out. BTW, was in your JNUC session "Moving Beyond Once Per” yesterday, excellent info :-)

talkingmoose
Moderator
Moderator

Thanks for that @TomDay! I appreciate that. :-)