Skip to content

Commit 8d05786

Browse files
authored
Create Reinstalls Jamf Framework for group
1 parent 6d37bb4 commit 8d05786

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

Reinstalls Jamf Framework for group

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
#Reinstalls Jamf Management Framework on every computer in a group
4+
5+
###########################
6+
7+
#Jamf credentials
8+
username=""
9+
password=""
10+
url="https://xxxxxx.jamfcloud.com"
11+
source credentials.sh
12+
13+
#Group ID number -- found in URL on computer group's page
14+
groupid=""
15+
16+
###########################
17+
18+
#Token function -- based on https://developer.jamf.com/jamf-pro/docs/jamf-pro-api-overview
19+
getBearerToken() {
20+
response=$(curl -s -u "$username":"$password" "$url"/api/v1/auth/token -X POST)
21+
bearerToken=$(echo "$response" | plutil -extract token raw -)
22+
tokenExpiration=$(echo "$response" | plutil -extract expires raw - | awk -F . '{print $1}')
23+
tokenExpirationEpoch=$(date -j -f "%Y-%m-%dT%T" "$tokenExpiration" +"%s")
24+
}
25+
26+
#get token
27+
getBearerToken
28+
29+
#pull XML data from Jamf, change it to a list
30+
31+
#curl: pull XML data based on group ID
32+
#xmllint: keep only the mobile device IDs from the XML (e.g. <id>456</id>)
33+
#1st sed: delete "<id>"s
34+
#2nd sed: replace "</id>"s with spaces
35+
#3rd sed: delete extra final space
36+
37+
devices=$(curl --request GET \
38+
--silent \
39+
--url $url/JSSResource/computergroups/id/$groupid \
40+
--header 'Accept: application/xml' \
41+
--header "Authorization: Bearer ${bearerToken}" \
42+
| xmllint --xpath "//computer/id" - \
43+
| sed 's/<id>//g' \
44+
| sed 's/<\/id>/ /g' \
45+
| sed 's/.$//')
46+
47+
#get total count of devices -- counting the number of "words" in $devices
48+
numberDevices=$(echo -n "$devices" | wc -w)
49+
50+
echo $numberDevices Devices
51+
echo
52+
echo 0 /$numberDevices
53+
54+
#iterate over the IDs in this device group
55+
56+
counter=0
57+
58+
for value in $devices
59+
do
60+
#redeploy Jamf management framework for $value
61+
curl --request POST \
62+
--silent \
63+
--url $url/api/v1/jamf-management-framework/redeploy/$value \
64+
--header 'accept: application/json' \
65+
--header "Authorization: Bearer $bearerToken" \
66+
--output /dev/null
67+
68+
#print status every 10
69+
let "counter+=1"
70+
if [[ $(expr $counter % 10) = "0" ]]
71+
then
72+
echo $counter /$numberDevices
73+
fi
74+
75+
#reset token every 500
76+
if [[ $(expr $counter % 500) = "0" ]]
77+
then
78+
getBearerToken
79+
fi
80+
81+
done
82+
echo $numberDevices /$numberDevices

0 commit comments

Comments
 (0)