-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJamfPro-CreateComputers.sh
More file actions
59 lines (50 loc) · 1.65 KB
/
JamfPro-CreateComputers.sh
File metadata and controls
59 lines (50 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Name: JamfPro-CreateComputers.sh
# Date: 2016/10/20
# Author: Luis Giraldo (luis@ook.co)
# Version: 1.0
# Purpose: Create computers in Jamf Pro Server from a CSV file containing a name (column 1) and serial (column 2)
#
# Script inspiration: https://www.jamf.com/jamf-nation/discussions/13118/api-and-post-command
#Define Variables
apiuser=<replacewithusername>
apipass=<replacewithpassword>
jamfProURL="https://<replacewithjamfproserverURL>:8443"
apiURL="JSSResource/computers/id/0"
xmlHeader="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
filepath="/path/to/sourcefile.csv"
#Backup the internal file separator
OLDIFS=$IFS
#Change the internal file separator
IFS=","
#Get number of records to process
recordqty=`awk -F, 'END {printf "%s\n", NR}' $filepath`
echo "Total records = ${recordqty}"
#Zero the counter
counter="0"
duplicates=[]
while read col1 col2
do
counter=$[$counter+1]
apiData="<computer><general><name>${col1}</name><serial_number>${col2}</serial_number><platform>Mac</platform></general></computer>"
output=`curl -sSkiu ${apiuser}:${apipass} "${jamfProURL}/${apiURL}" \
-H "Content-Type: text/xml" \
-d "${xmlHeader}${apiData}" \
-X POST`
#Error Checking
error=""
error=`echo $output | grep "Conflict"`
if [[ $error != "" ]]; then
echo "***Error creating record ${counter}: ${col2} ${col1}"
duplicates+=($col2)
else
echo "Added record ${counter}: ${col2} ${col1}"
fi
done < "${filepath}"
if [ ${#duplicates[@]} -eq 0 ]; then
echo "Process complete."
else
echo "The following serial numbers could not be created:"
printf '%s\n' "${duplicates[@]}"
fi
IFS=$OLDIFS