I have an an issue where I need to update some user fields in the API but I don't really know where to start.
In summary, I need to loop through all users and for every user whose 'managed_apple_id' field is blank/null I need to copy the data from the 'roster_managed_apple_id' field to the 'managed_apple_id' field.
#!/bin/bash
jssURL="https://xxxxx.jamfcloud.com"## DO NOT EDIT BELOW THIS LINE ##echo"Please enter your JSS username:"read jssUser
echo"Please enter your JSS password:"read-s jssPass
usersToGetAtOneTime="10000"# Make sure xmlstarlet is installedif ! command -v xmlstarlet > /dev/null ; thenecho"You must install xmlstarlet before using this script."echo"Try "brew install xmlstarlet""exit1fi# Get list of usersecho"Downloading list of user IDs..."whileread -r line; do
ids+=("$line")
done <<< "$(curl -X GET -k -s -u "$jssUser:$jssPass" "$jssURL/JSSResource/users" | xmlstarlet sel -t -v '/users/user/id')"# Find users with roster_managed_apple_id inecho"Gathering User Information"
count="$usersToGetAtOneTime"for id in"${ids[@]}"; do
managedAppleID=$(curl -X GET -k -s -u "$jssUser:$jssPass""$jssURL/JSSResource/users/id/$id" | xmlstarlet sel -t -v '/user/roster_managed_apple_id')
# Update Managed Apple ID if Roster Managed Apple ID Exists if [ -z "$managedAppleID" ]
thenecho"No Managed Apple ID, moving on"elseecho"$managedAppleID"
curl -X PUT -H "Accept: application/xml" -H "Content-type: application/xml" -k -u "$jssUser:$jssPass"-d"<user><managed_apple_id>$managedAppleID</managed_apple_id></user>""$jssURL/JSSResource/users/id/$id"
((count--))
fidoneexit0
#!/bin/bash
jssURL="https://xxxxx.jamfcloud.com"## DO NOT EDIT BELOW THIS LINE ##echo"Please enter your JSS username:"read jssUser
echo"Please enter your JSS password:"read-s jssPass
usersToGetAtOneTime="10000"# Make sure xmlstarlet is installedif ! command -v xmlstarlet > /dev/null ; thenecho"You must install xmlstarlet before using this script."echo"Try "brew install xmlstarlet""exit1fi# Get list of usersecho"Downloading list of user IDs..."whileread -r line; do
ids+=("$line")
done <<< "$(curl -X GET -k -s -u "$jssUser:$jssPass" "$jssURL/JSSResource/users" | xmlstarlet sel -t -v '/users/user/id')"# Find users with roster_managed_apple_id inecho"Gathering User Information"
count="$usersToGetAtOneTime"for id in"${ids[@]}"; do
managedAppleID=$(curl -X GET -k -s -u "$jssUser:$jssPass""$jssURL/JSSResource/users/id/$id" | xmlstarlet sel -t -v '/user/roster_managed_apple_id')
# Update Managed Apple ID if Roster Managed Apple ID Exists if [ -z "$managedAppleID" ]
thenecho"No Managed Apple ID, moving on"elseecho"$managedAppleID"
curl -X PUT -H "Accept: application/xml" -H "Content-type: application/xml" -k -u "$jssUser:$jssPass"-d"<user><managed_apple_id>$managedAppleID</managed_apple_id></user>""$jssURL/JSSResource/users/id/$id"
((count--))
fidoneexit0
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.