Skip to main content
Question

Use JSS "Department" value in Script?

  • August 9, 2017
  • 4 replies
  • 21 views

dstranathan
Forum|alt.badge.img+19

Can someone please give me a example on how to obtain a computer's assigned JSS "Department" value for use in a Bash script (that runs as a Policy payload)?

For various logistical reasons, I don't want to query Active Directory for dept info (using /usr/bin/dscl, etc) - I'd rather get it from the JSS. API calls, perhaps?

4 replies

Forum|alt.badge.img+5
  • New Contributor
  • August 9, 2017

You would need to use the JAMF API to get this information whilst in a script.

The following curl command should get you the department of a particular machine.

Please replace the variables with the values that are specific to you.

i.e $apiuser is the name of a JSS user account that is capable of accessing the API
$apipassword is that users password
$jamfServer is the URL of your JSS
$host is the name of the machine you want to get the information for.

If you're running this script via the jamf binary then you could substitute $host for $2 if you are trying to look up the machine that the script is runnining on. This is because when the JAMF binary runs scripts it automatically populates $1, $2 and $3 parameters and $2 is the hostname of the machine it is running on.

curl -k -H "accept: application/xml" -u $apiuser:$apipassword $jamfServer/JSSResource/computers/name/$host | xmllint --xpath "string(//computer/location/department)" -

I hope this helps.

Rob


dstranathan
Forum|alt.badge.img+19
  • Author
  • Valued Contributor
  • August 10, 2017

Thank you @r0blee. Your example was PERFECT.

I haven't played with API calls yet. This was a great introduction. Got my API 'brain juices' flowing!

Now that I have read some Jamf (and third-party) API documentation, I have several ideas I want to try out.


therealmacjeezy
Forum|alt.badge.img+5

I have a script that does this to computers based off of their computer name. This way I don't have to worry about setting the parameters for each site (currently have 19 sites so it would be tedious). I'll post it here once I get home if you'd like.


dstranathan
Forum|alt.badge.img+19
  • Author
  • Valued Contributor
  • August 11, 2017

Sounds good. The more info and "real-world" examples the better...