Last active
December 20, 2023 18:51
-
-
Save homebysix/ee4a7d615f755ee6eaa68043cdb1ddff to your computer and use it in GitHub Desktop.
delete_jamf_remote_policies.py
This file contains hidden or 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
"""This script leverages the jamf-pro-sdk module to remove policies left over | |
from usage of the deprecated Jamf Remote app. | |
""" | |
import re | |
from jamf_pro_sdk import JamfProClient, PromptForCredentials | |
def main(): | |
"""Main process.""" | |
api = JamfProClient( | |
server="example.jamfcloud.com", credentials=PromptForCredentials() | |
) | |
# Get all Jamf policies | |
policies = api.classic_api_request("GET", "policies").json().get("policies") | |
# Filter for policies that match Remote naming convention | |
remote_pattern = r"[\d\-]+ at [\d:]+ (A|P)M \| [\w\-\.@]+ \| [\d]+ Computers?" | |
remote_policies = [x for x in policies if re.search(remote_pattern, x["name"])] | |
print(f"Found {len(remote_policies)} remote policies.") | |
# Delete Remote policies | |
for remote_policy in remote_policies: | |
pid = remote_policy["id"] | |
print(f'Removing policy ID {pid}: {remote_policy["name"]}') | |
_ = api.classic_api_request("DELETE", f"policies/id/{pid}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment