Using the Department and Building names in a script

RevIT
New Contributor

Hello,

I'm wanting to run a script which does different things based on the computers Building and/or Department.

For example, I use Munki also for managing specific apps that are a lot easier to deploy and update using Munki than they are using Jamf (sorry Jamf)... As a result, I would like to run a script on the concept of "If Department = Audio then set Munki Manifest to Audio"

Yes, I know I could simply write a script to set the manifest to Audio and only scope it to Audio Department, but I'd have to create an individual script for each department, then create a policy for each script and scope them accordingly - This is time consuming and adds clutter so would like one policy that runs on all computers, and I scope it to all departments so this would be much easier.

1 REPLY 1

Chris
Valued Contributor

You can get that info from the API and use it in your script like so:

#!/bin/bash

API_URL=https://your.jamf.url/JSSResource
API_USER=user_with_read_permissions
API_PASS=PaSsWoRd

# Get serial number
myserial=$(system_profiler SPHardwareDataType | awk '/Serial Number/{print $4}')

# Get department
department=$(curl -sku "$API_USER":"$API_PASS" 
-X GET 
-H "accept: text/xml" 
"$API_URL"/computers/serialnumber/$myserial | xmllint --xpath '/computer/location/department/text()' -)