Hi, I'm new to Jamf Pro and the Apple world and I'm utilising this fantastic API script here. I am wanting to see if a Computer object is a member of a Static group, if so, remove that object from that group. Is this possible?
I'm assuming that I can use this to GET the object (variables are defined at the top of my script):
apiURL="JSSResource/computergroups/id/${StaticGroupID}"
apiData="<computer_group><id>${StaticGroupID}</id><name>${StaticGroupName}</name><computer_additions><computer><name>$ComputerName</name></computer></computer_additions></computer_group>"
group_check=$(curl -s \\
--header "Authorization: Bearer ${api_token}" --header "Content-Type: text/xml" \\
--url "${jamfpro_url}/${apiURL}" \\
--data "${apiData}" \\
--request GET > /dev/null)
if [[ ${group_check} -ne 200 ]]; then
echo "Device is no longer assigned to static group. Will not proceed."
fi
exit 0
Next, if that Computer is assigned to that Group, I want to unassign it, but I only see API functions to DELETE a group or computer object and nothing to remove a computer from a group.
https://developer.jamf.com/jamf-pro/reference/computergroups
Basically the goal here is, assign computers to a Static group to make "Erase and Install macOS" available to that computer in Self Service. When the policy is triggered, remove the computer from that group, then run Erase and Install - This is just a failsafe in case admins forget to remove the computer assignment from the Static group after the erase has been triggered, as we don't want Erase and Install available to devices all the time. Only on a case by case basis.
I appreciate any help you can give here.