-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet_Remove_App_When_MDM_Removed.py
63 lines (46 loc) · 2.41 KB
/
Set_Remove_App_When_MDM_Removed.py
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
#!/usr/bin/env python3
# Matthew Prins 2024
# https://github.com/MatthewPrins/Jamf/
# check as TRUE "Remove app when MDM profile is removed" for all apps where it is currently FALSE
# pip install requests if not already done
import json
import requests
from datetime import datetime
############################
# Editable variables
# Jamf credentials
username="xxxxxx"
password="xxxxxx"
jamfurl="https://xxxxxx.jamfcloud.com"
############################
# definition for fetching API token
def fetchtoken():
response = requests.post(url=jamfurl + "/api/v1/auth/token", headers={'Accept': 'application/json'}, auth=(username, password))
print("new token fetched\n")
return response.json()['token'], datetime.strptime(response.json()['expires'], '%Y-%m-%dT%H:%M:%S.%fZ')
# definition for invalidating API token
def invalidatetoken():
response = requests.post(url=jamfurl + "/api/v1/auth/invalidate-token", headers={'Authorization': 'Bearer ' + token})
############################
# get initial token
token,tokenexpiration = fetchtoken()
# import mobile app data from API as a dictionary
response = requests.get(jamfurl + "/JSSResource/mobiledeviceapplications", headers={'Accept': 'application/json','Authorization': 'Bearer ' + token})
appdictionary = json.loads(response.text)
# iterate through ids in appdictionary and add to idlist
idlist=[]
for entry in appdictionary["mobile_device_applications"]:
idlist.append(entry["id"])
print (str(len(idlist)) + " apps\n")
print ('Apps updated to TRUE for "Remove app when MDM profile is removed":')
#iterate through all apps
for id in idlist:
#get current app status on app removal when MDM is removed
response = requests.get(jamfurl + "/JSSResource/mobiledeviceapplications/id/" + str(id), headers={'Accept': 'application/json','Authorization': 'Bearer ' + token})
appname = json.loads(response.text)["mobile_device_application"]["general"]["name"]
#for apps where it is FALSE, update to TRUE
if not json.loads(response.text)["mobile_device_application"]["general"]["remove_app_when_mdm_profile_is_removed"]:
response = requests.put(jamfurl + "/JSSResource/mobiledeviceapplications/id/" + str(id), data="<mobile_device_application><general><remove_app_when_mdm_profile_is_removed>true</remove_app_when_mdm_profile_is_removed></general></mobile_device_application>", headers={'Accept': 'application/xml','Authorization': 'Bearer ' + token})
print (appname)
print ("done!")
exit()