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