-
Notifications
You must be signed in to change notification settings - Fork 13
/
Office_License.sh
167 lines (141 loc) · 5.36 KB
/
Office_License.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/zsh
#set -x
: <<ABOUT_THIS_SCRIPT
-----------------------------------------------------------------------
Written by: Paul Bowden
Software Engineer
Microsoft Corporation
https://github.com/pbowden-msft/ExtensionAttributes
Adapted from a script by: William Smith
Professional Services Engineer
Jamf
https://github.com/talkingmoose/Casper-Scripts
Last updated: April 7, 2021
Originally posted: January 7, 2017
Purpose: Use this script as part of an extension attribute in Jamf
to report the type of Microsoft Office license in use.
Except where otherwise noted, this work is licensed under
http://creativecommons.org/licenses/by/4.0/
"Communication happens when I know that you know what I know."
INSTRUCTIONS
1) Log in to the Jamf Pro server.
2) Navigate to JSS Settings > Computer Management > Extension Attributes.
3) Click the " + " button to create a new extension attribute with these settings:
Display Name: Office License
Description: Reports Office license in use.
Data Type: String
Inventory Display: Extension Attributes
Input Type: Script
Script: < Copy and paste this entire script >
4) Save the extension attribute.
5) Use Recon.app or "sudo jamf recon" to inventory a Mac with Office installed.
6) View the results under the Extension Attributes payload
of the computer's record or include the extension attribute
when adding criteria to an Advanced Computer Search or Smart Group.
-----------------------------------------------------------------------
ABOUT_THIS_SCRIPT
# Constants
PERPETUALLICENSE="/Library/Preferences/com.microsoft.office.licensingV2.plist"
# Detects the presence of a perpetual license
DetectPerpetualLicense() {
if [ -f "$PERPETUALLICENSE" ]; then
/bin/echo "Yes"
else
/bin/echo "No"
fi
}
# Detects single vs. stacked license
DetectStackedLicense() {
if [ -f "$PERPETUALLICENSE" ]; then
LINECOUNT=$(/usr/bin/wc -l "$PERPETUALLICENSE" | awk {'print $1'})
if [ "$LINECOUNT" = "125" ]; then
/bin/echo "Yes"
else
/bin/echo "No"
fi
fi
}
# Determines what type of perpetual license the machine has installed
PerpetualLicenseType() {
if [ -f "$PERPETUALLICENSE" ]; then
if /usr/bin/grep -q "Bozo+MzVxzFzbIo+hhzTl43O7w5oMsJ7M3Q4vhvz/j" "$PERPETUALLICENSE"; then
/bin/echo "Office 2021 Preview Volume License"
return
fi
if /usr/bin/grep -q "Bozo+MzVxzFzbIo+hhzTl4xkRZSjOUX8J8nIgpXuMa" "$PERPETUALLICENSE"; then
/bin/echo "Office 2021 Volume License"
return
fi
if /usr/bin/grep -q "A7vRjN2l/dCJHZOm8LKan11/zCYPCRpyChB6lOrgfi" "$PERPETUALLICENSE"; then
if [ "$STACKED" = "Yes" ]; then
/bin/echo "Office 2021/2019 Volume License (Stacked)"
return
else
/bin/echo "Office 2019 Volume License"
return
fi
fi
if /usr/bin/grep -q "Bozo+MzVxzFzbIo+hhzTl4JKv18WeUuUhLXtH0z36s" "$PERPETUALLICENSE"; then
/bin/echo "Office 2019 Preview Volume License"
return
fi
if /usr/bin/grep -q "A7vRjN2l/dCJHZOm8LKan1Jax2s2f21lEF8Pe11Y+V" "$PERPETUALLICENSE"; then
/bin/echo "Office 2016 Volume License"
return
fi
if /usr/bin/grep -q "DrL/l9tx4T9MsjKloHI5eX" "$PERPETUALLICENSE"; then
/bin/echo "Office 2016 Home and Business License"
return
fi
if /usr/bin/grep -q "C8l2E2OeU13/p1FPI6EJAn" "$PERPETUALLICENSE"; then
/bin/echo "Office 2016 Home and Student License"
return
fi
if /usr/bin/grep -q "Bozo+MzVxzFzbIo+hhzTl4m" "$PERPETUALLICENSE"; then
/bin/echo "Office 2019 Home and Business License"
return
fi
if /usr/bin/grep -q "Bozo+MzVxzFzbIo+hhzTl4j" "$PERPETUALLICENSE"; then
/bin/echo "Office 2019 Home and Student License"
return
fi
/bin/echo "Office Perpetual License"
fi
}
# Creates a list of local usernames with UIDs above 500 (not hidden)
DetectO365License() {
userList=$( /usr/bin/dscl /Local/Default -list /Users uid | /usr/bin/awk '$2 >= 501 { print $1 }' )
while IFS= read -r aUser
do
# get the user's home folder path
homePath=$( eval /bin/echo ~$aUser )
# list of potential Office 365 activation files
O365SUBMAIN="$homePath/Library/Group Containers/UBF8T346G9.Office/com.microsoft.Office365V2.plist"
O365SUBNEW="$homePath/Library/Group Containers/UBF8T346G9.Office/Licenses/5"
O365SUBBAK1="$homePath/Library/Group Containers/UBF8T346G9.Office/com.microsoft.O4kTOBJ0M5ITQxATLEJkQ40SNwQDNtQUOxATL1YUNxQUO2E0e.plist"
O365SUBBAK2="$homePath/Library/Group Containers/UBF8T346G9.Office/O4kTOBJ0M5ITQxATLEJkQ40SNwQDNtQUOxATL1YUNxQUO2E0e" # hidden file
# checks to see if an O365 subscription license file is present for each user
if [ -f "$O365SUBMAIN" ] || [ -f "$O365SUBBAK1" ] || [ -f "$O365SUBBAK2" ] || [ -d "$O365SUBNEW" ]; then
activations=$((activations+1))
fi
done <<< "$userList"
# Returns the number of activations to O365ACTIVATIONS
/bin/echo $activations
}
## Main
PERPETUALPRESENT=$(DetectPerpetualLicense)
STACKED=$(DetectStackedLicense)
O365ACTIVATIONS=$(DetectO365License)
LICTYPE=$(PerpetualLicenseType)
if [ "$PERPETUALPRESENT" = "Yes" ] && [ "$O365ACTIVATIONS" ]; then
/bin/echo "<result>$LICTYPE and Office 365 licenses detected</result>"
elif [ "$PERPETUALPRESENT" = "Yes" ]; then
/bin/echo "<result>$LICTYPE</result>"
elif [ "$O365ACTIVATIONS" ]; then
/bin/echo "<result>Office 365 activations: $O365ACTIVATIONS</result>"
elif [ "$PERPETUALPRESENT" = "No" ] && [ ! "$O365ACTIVATIONS" ]; then
/bin/echo "<result>No license</result>"
fi
exit 0