API: Show all Policies that are associated with a specific script.

FritzsCorner
Contributor III

I am looking for a way to pull a report via the JSS API to show all the Policies that are associated with a specific script. Looking through the API, I don't see any simple way of finding this information.

I have been able to accomplish this via a MySQL query similar to this:

SELECT
    scripts.file_name,
    scripts.script_id,
    policies.name,
    policies.policy_id
FROM policy_scripts
INNER JOIN scripts
ON scripts.script_id = policy_scripts.script_id
INNER JOIN policies
ON policies.policy_id = policy_scripts.policy_id
WHERE scripts.file_name = "Super Awesome Script";

This query would return the the data in the following format:

file_name               script_id   name                     policy_id
Super Awesome Script    165         Super Awesome Policy 1   1645
Super Awesome Script    165         Super Awesome Policy 2   2314
Super Awesome Script    165         Super Awesome Policy 3   2356

Is there anyway to achieve the same thing via the API that I am missing?

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

I only wish this were easy. Unfortunately, there is no one single function that will get you this info from the API. That being said, I'm certain it can be scripted, but it will be somewhat ugly and will likely take time to generate your final report.
You can take a look at some of my Casper-API scripts posted to my github page for examples on how I've built some reporting around the API, to do other but similar things. Forewarning, its fairly clunky since you have no choice but to pull down an xml of each policy and scan the data for the specific script or package ID you're looking for and then add any it finds into an array or append it to a file, etc. Better than nothing, but I sincerely wish JAMF would beef up the API for this kind of stuff.

View solution in original post

5 REPLIES 5

mm2270
Legendary Contributor III

I only wish this were easy. Unfortunately, there is no one single function that will get you this info from the API. That being said, I'm certain it can be scripted, but it will be somewhat ugly and will likely take time to generate your final report.
You can take a look at some of my Casper-API scripts posted to my github page for examples on how I've built some reporting around the API, to do other but similar things. Forewarning, its fairly clunky since you have no choice but to pull down an xml of each policy and scan the data for the specific script or package ID you're looking for and then add any it finds into an array or append it to a file, etc. Better than nothing, but I sincerely wish JAMF would beef up the API for this kind of stuff.

FritzsCorner
Contributor III

Thanks @mm2270

That's what I was afraid of. I think I may just stick to MySQL Queries for simple reports for the time being. I discovered that even with the SQL Query, Casper Remote installs are lumped in as a Policy. I need to work on something to filter those results out.

I really just wanted a quick at-a-glance way of knowing if a script was actively associated with any Policies. JAMF leaves a lot to be desired in terms of good script organization right now. Same thing for Smart Groups, Static Groups, etc. Guess I will have to search the feature requests to see if I need to submit a new one or not. :)

Thanks again!

thoule
Valued Contributor II

I have a messy and slow script on my github repo

https://github.com/tmhoule/JSSReport/blob/master/cleanup.sh

It will output unused scripts and groups.

EDIT: Scripts used in configurations for imaging may show up as unused; not sure if I fixed that yet or not.

FritzsCorner
Contributor III

Thanks @thoule

I will take a look at this.

Josh_Smith
Contributor III
I really just wanted a quick at-a-glance way of knowing if a script was actively associated with any Policies.

@FritzsCorner When I want to see if a particular script/package is in use I just paste its name into the search box under Policies to see which policies it is in:
5325c0dfc62a449a84b888912f5996e5
759af2832fd34792a3f632bbfb9d9a63

Obviously this doesn't scale well and is just for quick checks, but it is handy.