Importing Departments into JamfPro from a CSV

MadPossum
New Contributor III

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!

10 REPLIES 10

dgreening
Valued Contributor II

You can, but you need to leverage the API to do it.

mm2270
Legendary Contributor III

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?

MadPossum
New Contributor III

Hi!

It's very straight forward. Department is the header and the departments just fall below as in the pic below:

622f76b19fa84f338dfc3249ade9c97b

flyboy
Contributor

@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.

hkabik
Valued Contributor
#!/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/&/&amp;/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

bumbletech
Contributor III

And there's always the MUT: http://jssmut.weebly.com/

MadPossum
New Contributor III

Thank you all for the responses! I'm going to try @hkabik 's script against my test.jss and see what the results are. @jbourdon, I didn't know The MUT was able to update an attribute without an associated machine record. Am I mistaken about that?

odnlinx
New Contributor II

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

quentinIT
New Contributor

I'm getting connection errors as well. @odnlinx did you ever find another script?

fgonzale
Contributor

@odnlinx @quentinIT A working script for importing Departments into Jamf via CSV file is listed in this newer thread: Bulk update Departments/Buildings