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
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.
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.
Sounds good. The more info and "real-world" examples the better...