Created
February 11, 2019 16:27
-
-
Save poundbangbash/641d170bdefb1bfc2c86ba4975659fa3 to your computer and use it in GitHub Desktop.
Munki fact to check if MDM is Installed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''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