Script to automatically add a system to Scope - 'Target' of a Policy in JSS

ds1987
New Contributor

As we are moving towards automation and trying to create an environment where everything can be available in Self-service i need to implement an idea of a script or anything which will help me in completing the below.

A policy will be available in Self-service and on clicking on 'Install' it will identify the Hostname of the system, (That i know to get and store it in a variable) then it will add the hostname to Scope - 'Target' of a Policy in JSS/JAMF or Exclusion list of a ploci in JSS/JAMF and execute the later part. The rest past is ready and tested but i am unable to figure out this part.

Any help would be very helpfull for me

2 REPLIES 2

davidacland
Honored Contributor II
Honored Contributor II

It sounds like you want to have a self service policy, that adds a Mac to the scope of another policy.

How do they get scoped to the first policy? Could they just be scoped to the second policy to cut out the middle man?

If that won't work in this scenario, you can have a script to add devices to the scope. It can be done in bash or python, depending on which you want to work with.

In bash, you would create a block of XML and upload it using curl.

There are some good examples of the XML on your jamf server: https://your.jamf.server/api

Geelcey
New Contributor III
New Contributor III

You could possibly create a new computer extension attribute called 'test' for example and scope policies to that extension attribute and once the computer has a value of 'yes' or whatever you choose the policy sees the value and pushes out policies. You can use the API to add a large number of machines to the extension attribute in one script and will take seconds rather than doing it manually.

So in a nutshell ..

you can run the script from your Mac -> it updates the extension attribute for all machines you've added in your CSV (serial, name or computer id) -> Pulls down the policies you have assigned to that extension attribute -> done.

I have just spent the last few weeks delving into the JSS API and I have done something similar above, let me know if this is something you feel could work and I would be happy to help.