Update OfficeActiviationEmailAddress with script

AJPinto
Honored Contributor II

I am trying to update the com.microsoft.office plist to add the UPN of the current logged in user to OfficeActiviationAddress. I am wanting to do it off a script rather then a configuration profile so I dont have to unscope and rescope a device whenever it changes hands to update this value. I have it working fine with a configuration profile but configuration profiles lacking the ability to self update is a massive issue which is really preventing me from implementing it. My end goal is to set a script to update OfficeActiviationEmailAddress of a reoccurring checkin. If anyone has a different way I am all ears, and thanks for any help or advice.

When I run the script below nothing happens, both when being run with JAMF and being run locally with terminal. I have tried not defining the path for the plist as well and nothing. If I point it to the desktop it will create the plist with the value but obviously it does not do much good being on the desktop :).

#!/bin/sh
#Define current logged in user
DIV1='echo ####################################################################'
DIV2='echo --------------------------------------------------------------------'
DIV3='echo ....................................................................'
ActiveUser=`/bin/ls -l /dev/console 
| /usr/bin/awk '{ print $3 }' 
| tr "[a-z]" "[A-Z]"`
ActiveUserRealName=`dscl . -read /Users/$ActiveUser 
| grep RealName: 
| cut -c11-`
if [[ -z $ActiveUserRealName ]]; then
 ActiveUserRealName=`dscl . -read /Users/$ActiveUser 
| awk '/^RealName:/,/^RecordName:/' 
|sed -n 2p | cut -c 2-`
fi

#Define UPN for current logged in user
UseruserPrincipalName=$(dscl "/Active Directory/CORP/All Domains" -read Users/$ActiveUser | grep "dsAttrTypeNative:userPrincipalName")

#update com.microsoft.office.plist with the UPN for the current logged in user
defaults write /Library/Managed Preferences/$ActiveUser/com.microsoft.office.plist OfficeActivationEmailAddress -string '$UseruserPrincipalName'
0 REPLIES 0