Managing Mobile Device Names

VT-Vincent
New Contributor III

I'm curious how everyone is managing device names - I know that you can change/enforce them on a one-by-one basis or via a PreStage Enrollment but this doesn't do much for an existing deployment. Is there any way to batch change/enforce names?

If not, is it possible to hide the Device Name from display? It seems even if you remove the field from Inventory Display, it doesn't have an effect. Not sure about other deployments, but in mine, this isn't terribly useful :P

781fc18972e84ac8b5979eeedb9af178

3 REPLIES 3

St0rMl0rD
Contributor III

We enforce our device names. This is possible with iOS 8.0 or newer. We use full name of the user for the device name, so every time the device inventory is updated, it's updated with user's real name.

VT-Vincent
New Contributor III

Yes, I know it was added in but like I mentioned, I was wondering if there was a method to set this setting in a batch process. Ideally it would be part of the PreStage Enrollment but the problem is we deployed before this setting was available so it's not an option. I'd be looking to set this on 700+ devices.

I was also wondering if it was possible to simply hide the name from inventory display, as it doesn't serve a purpose.

jrwilcox
Contributor

Well, I have found a way to do this but it is not the most elegant script I have ever written:

#!/bin/bash

#  enableNameSet.sh
#  
#
#  Created by James Wilcox on 7/1/15.
#

# check for directory

#should I delete the temp files
delete=true

# my read only api logon
user_name=$4
password=$5

# Our Base Address
base=$6

# Our JSS Address
jss=$base/JSSResource

# Group we are using to limit change
group=$7

#temp file names
device=temp01.xml
groupxml=temp02.xml

#
#   Use Applescript to set the info in the JSS GUI
#   This requires the user to be logged in with write privledges
#

function pushNameToDevice { #1 device ID #2 Name
/usr/bin/osascript <<EOT
    tell application "Safari"
        activate
        set URL of document 1 to "$base/mobileDevices.html?id=$1&o=r"
        delay 2
        do JavaScript "editGeneral()" in document 1
        delay 2
        do JavaScript "document.getElementById('FIELD_DEVICE_NAME_TYPE').checked ='true';" in document 1
        delay 3
        do JavaScript "saveGeneralChanges()" in document 1
        delay 2
        do JavaScript "editGeneral()" in document 1
        delay 2
        do JavaScript "document.getElementById('FIELD_DEVICE_NAME').value ='$2';" in document 1
        delay 2
        do JavaScript "saveGeneralChanges()" in document 1
        delay 2
    end tell
EOT
}

#
#   Read the iPad info to see if we need to set the name
#

function doMobileDeviceName { #1 device ID
    echo -n "  reading Mobile Device record $1"
    curl -sSf -u $user_name:$password --header "Accept: application/xml" $jss/mobiledevices/id/$1 --request GET --output $device
    error=$?
    if [ $error -ne 0 ]; then
        echo "curlError = $error"
        if [ "$delete" = "true" ]; then rm -rf $device; fi
        return
    fi
    # read device name from xml device record
    device_name=$(xmllint $device --xpath 'mobile_device/general/device_name/text()')
    # read full name from xml device record
    full_name=$(xmllint $device --xpath 'mobile_device/location/real_name/text()')
    # Check and make sure we have something in Full Name
    if [ ! -z "$full_name" ]; then
        # Check to see if the name is set already
        if [ "$device_name" != "$full_name" ]; then
            pushNameToDevice $1 "$full_name"
            echo -n " Push"
            numberPushed=$[$numberPushed+1]
        fi
    fi
    echo
    if [ "$delete" = "true" ]; then rm -rf $device; fi
}

#
#   Main
#

numberPushed='0'
echo "  reading Group $group"
# grab the Mobile Device Group Info from the JSS in XML Format
curl -sSf -u $user_name:$password --header "Accept: application/xml" "$jss/mobiledevicegroups/name/$group" --request GET --output $groupxml
error=$?
if [ $error -ne 0 ]; then
    echo "curlError = $error"
    if [ "$delete" = "true" ]; then rm -rf $groupxml; fi
    exit
fi
size=$(xmllint $groupxml --xpath "mobile_device_group/mobile_devices/size/text()")
echo "There are $size iPads in the group"
i=$size
while [ $i -gt 0 ]; do
    doMobileDeviceName "$(xmllint $groupxml --xpath "mobile_device_group/mobile_devices/mobile_device[$i]/id/text()")"
    i=$[$i-1]
done
if [ "$delete" = "true" ]; then rm -rf $groupxml; fi
echo "There are $size iPads in the group"
echo "There were $numberPushed iPads that needed the name set"

exit 0

The script will read the members from a group in your JSS. It will then check to see if the device name is equal to the full name in the user section. If it is not it will attempt to enable force naming and set the name. You may need to adjust the delays in the Applescript section. These did seem to work for us and our JSS is cloud hosted.