iPhone,  Mac OS X,  Mac OS X Server,  Mac Security

Exporting Information From iPhone Configuration Utility

In a previous post I looked at automating iPhone and iPad deployment. There, we looked at the iPhone Configuration Utility. Now that Profile Manager is built into Mac OS X Server in Lion, and with the number of 3rd party MDM solutions on the market, many users of iPhone Configuration Utility are looking to extract information from it and move it into other places. Many of these places can import property lists.

If you look at the file header for .mobileconfig and .deviceinfo files you’ll notice that they begin with the familiar:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>

Given that .mobileconfig and .deviceinfo files are property lists with different extensions, if you want to turn them into property lists, simply rename them. Given that many people will have 100s or 1000s of devices, this is something that most will want to automate. So, let’s use a basic for loop to do so. The following will convert .mobileconfig files into plist:

for x in ~/Library/MobileDevice/Configuration Profiles/*.mobileconfig; do mv $x `basename $x .mobileconfig`.plist; done;

This will put them back:

for x in ~/Library/MobileDevice/Configuration Profiles/*.plist; do mv $x `basename $x .plist`.mobileconfig; done;

Or to convert the device information to property lists:

for x in ~/Library/MobileDevice/Devices/*.deviceinfo; do mv $x `basename $x .deviceinfo`.plist; done;

Or property lists to device information:

for x in ~/Library/MobileDevice/Devices/*.plist; do mv $x `basename $x .plist`.deviceinfo; done;

Once files are converted then you can also automate crawling through them to obtain information. For example, to pull the information from the two fields in iPhone Configuration Utility that are user editable, ownerName and ownerEmail as well as the serial number of a device with a deviceIdentifier of 26c2d1b2a68c7862bd4c6bfbe708517964733cf3:

defaults read ~/Library/MobileDevice/Devices/26c2d1b2a68c7862bd4c6bfbe708517964733cf3 ownerEmail

defaults read ~/Library/MobileDevice/Devices/26c2d1b2a68c7862bd4c6bfbe708517964733cf3 ownerName

You could then redirect this output into a csv file, perhaps grabbing other information such as:

  • UniqueChipID
  • deviceActivationState
  • deviceBluetoothMACAddress
  • deviceBuildVersion
  • deviceCapacityKey
  • deviceClass
  • deviceIdentifier (also the basename of the file)
  • deviceLastConnected
  • deviceName
  • deviceProductVersion
  • deviceType
  • deviceWiFiMACAddress

And then there are 3 arrays that wouldn’t likely look great in a csv, but could easily be brought out automatically:

  • provisioningProfiles: useful if you are duplicating provisioning profile information into an mdm solution
  • configurationProfiles: useful if you are duplicating configuration profile information from devices into an mdm solution
  • applicationDictionaries: great for pulling off what apps are where

You can get all of this without moving the files to plist as well, but in this example I am making an assumption that you will be importing these devices via plist and so you would be converting them anyway. The ability to dump information into a csv for reporting or other types of imports is ancillary. Having said this, I’ve taken it all and wrapped it into a shell script:

echo deviceIdentifier,deviceSerialNumber,ownerName,ownerEmail,UniqueChipID,deviceActivationState,deviceBluetoothMACAddress,deviceBuildVersion,deviceCapacityKey,deviceClass,deviceLastConnected,deviceName,deviceProductVersion,deviceWiFiMACAddress,deviceType > ~/mydevices.csv
for deviceID in *.deviceinfo; do mv "$deviceID" "`basename "$deviceID" .deviceinfo`.plist";
deviceID=${deviceID%.deviceinfo}
deviceserialnumber=`defaults read ~/Library/MobileDevice/Devices/$deviceID deviceSerialNumber`
ownerName=`defaults read ~/Library/MobileDevice/Devices/$deviceID ownerName`
ownerEmail=`defaults read ~/Library/MobileDevice/Devices/$deviceID ownerEmail`
UniqueChipID=`defaults read ~/Library/MobileDevice/Devices/$deviceID UniqueChipID`
deviceActivationState=`defaults read ~/Library/MobileDevice/Devices/$deviceID deviceActivationState`
deviceBluetoothMACAddress=`defaults read ~/Library/MobileDevice/Devices/$deviceID deviceBluetoothMACAddress`
deviceBuildVersion=`defaults read ~/Library/MobileDevice/Devices/$deviceID deviceBuildVersion`
deviceCapacityKey=`defaults read ~/Library/MobileDevice/Devices/$deviceID deviceCapacityKey`
deviceClass=`defaults read ~/Library/MobileDevice/Devices/$deviceID deviceClass`
deviceLastConnected=`defaults read ~/Library/MobileDevice/Devices/$deviceID deviceLastConnected`
deviceName=`defaults read ~/Library/MobileDevice/Devices/$deviceID deviceName`
deviceProductVersion=`defaults read ~/Library/MobileDevice/Devices/$deviceID deviceProductVersion`
deviceType=`defaults read ~/Library/MobileDevice/Devices/$deviceID deviceType`
deviceWiFiMACAddress=`defaults read ~/Library/MobileDevice/Devices/$deviceID deviceWiFiMACAddress`
echo $deviceID,$deviceserialnumber,$ownerName,$ownerEmail,$UniqueChipID,$deviceActivationState,$deviceBluetoothMACAddress,$deviceBuildVersion,$deviceCapacityKey,$deviceClass,$deviceLastConnected,$deviceName,$deviceProductVersion,$deviceWiFiMACAddress,$deviceType >> ~/mydevices.csv
done;

This script (which should have a bit more logic put into it for defining things, etc) should convert all of your .deviceinfo files to property list while building a csv of their contents (minus the arrays, which I didn’t think prudent to put into csv but which could be thrown in there pretty easily) in ~/mydevices.csv (or my devices.csv in your home directory). ProfileManager can definitely import device holders, which you should be able to do with a couple of columns of this output…

And to undo the conversion to plist (if you didn’t actually mean to do that part):

for x in ~/Library/MobileDevice/Devices/*.plist; do mv $x `basename $x .plist`.deviceinfo; done;