Skip to content

Instantly share code, notes, and snippets.

@poundbangbash
Created February 11, 2019 16:27
Show Gist options
  • Save poundbangbash/641d170bdefb1bfc2c86ba4975659fa3 to your computer and use it in GitHub Desktop.
Save poundbangbash/641d170bdefb1bfc2c86ba4975659fa3 to your computer and use it in GitHub Desktop.
Munki fact to check if MDM is Installed
'''Check MDM install status'''
import subprocess
import plistlib
import sys
def fact():
'''Check MDM install status'''
cmd = ['/usr/bin/profiles', '-C', '-o', 'stdout-xml']
run = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err = run.communicate()
try:
plist = plistlib.readPlistFromString(output)
except: # noqa
plist = {'_computerlevel': []}
try:
for possible_plist in plist['_computerlevel']:
for item_content in possible_plist['ProfileItems']:
try:
profile_type = item_content['PayloadType']
except KeyError:
profile_type = ''
if profile_type == 'com.apple.mdm':
return {'isMDMInstalled': True}
except KeyError:
return {'isMDMInstalled': False}
return {'isMDMInstalled': False}
if __name__ == '__main__':
print fact()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment