Use JSS "Department" value in Script?

dstranathan
Valued Contributor II

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 4

r0blee
New Contributor III

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
Valued Contributor II

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
New Contributor III

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.

"Saying 'uhh..' is the human equivalent to buffering."

dstranathan
Valued Contributor II

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