Posted on 08-07-2017 09:15 AM
Hi all!
The Departments in our JamfPro instance were a mess, Nothing was pulling from AD because of all the miss matches. I've cleaned all of that cruft out and now I want to add the Departments as exported from our AD.
The question I have is, can I import a CSV of Departments into our JamfPro?
Thanks in advance!
Posted on 08-07-2017 09:22 AM
You can, but you need to leverage the API to do it.
Posted on 08-07-2017 09:31 AM
Yes, you should be able to do this, but it would need to be with an API script. There's nothing native in the UI I don't think that will let you directly import that csv file. Plus, to work correctly, the csv will probably need to have the correct columns and format. But it should be possible to do it.
Can you post an example, scrubbed if needed, of how the csv you received is formatted? Like what a typical row looks like and the headers in it?
Posted on 08-07-2017 10:19 AM
Hi!
It's very straight forward. Department is the header and the departments just fall below as in the pic below:
Posted on 08-07-2017 10:42 AM
@MadPossum, @mm2270 posted a script here for populating static groups based off a text file. It would be easy to modify to do departments. I've done it with network segments.
Posted on 08-07-2017 10:45 AM
#!/bin/bash
#Declare variables
server="" #Server name
username="" #JSS username with API privileges
password="" #Password for the JSS account
file="" #Path to CSV
#Do not modify below this line
#Variables used to create the XML
a="<department><name>"
b="</name></department>"
#Count the number of entries in the file so we know how many Departments to submit
count=$(cat -n ${file} | tail -n 1 | cut -f1 | xargs)
#Set a variable to start counting how many Departments we've submitted
index="0"
#Loop through the Department names and submit to the JSS until we've reached the end of the CSV
while [ $index -lt ${count} ]
do
#Increment our counter by 1 for each execution
index=$[$index+1]
#Set a variable to read the next entry in the CSV
var=`cat ${file} | sed 's/&/&/g'| awk -F, 'FNR == '$[$index]' {print $1}'`
#Output the data and XML to a file
echo "${a}""${var}""${b}" > /tmp/test.xml
#Submit the data to the JSS via the API
curl -k -v -u ${username}:${password} https://${server}:8443/JSSResource/departments/name/Name -T "/tmp/test.xml" -X POST
done
#Clean up the temporary XML file
rm /tmp/test.xml
exit 0
Posted on 08-07-2017 10:50 AM
And there's always the MUT: http://jssmut.weebly.com/
Posted on 08-07-2017 12:01 PM
Posted on 02-21-2020 01:08 PM
Hello,
Resurrecting this thread. I was wondering if there was a similar script for the new uapi. I tried using the script here and was getting connection errors.
Thank
Posted on 05-20-2020 09:49 AM
I'm getting connection errors as well. @odnlinx did you ever find another script?
Posted on 01-31-2021 09:25 PM
@odnlinx @quentinIT A working script for importing Departments into Jamf via CSV file is listed in this newer thread: Bulk update Departments/Buildings