need some help removing user and location data in bulk

jchurch
Contributor II

we replaced our fleet of teacher laptops with new ones. the old teacher laptop will be going into carts for use in the classroom. we had pulled al the user/building/department info from AD, but now that they will be going into carts for student use all that info needs to be removed. thats where i hit the wall. i can fill this info in bulk, but how do you remove it?

any help would be appreciated

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

Unfortunately the jamf recon with blanks does not work. At one time you could send a space instead of a null value to the recon and it worked, but once the JSS moved to version 9.x it stopped working. The only way in my testing I've been able to do it is with an API script, as mentioned on the linked thread. That was the script I was referring to, but as I mentioned, that won't do a bulk operation. It requires each Mac to run a policy to run the script to blank out its own record. If the Macs are still in use right now it may be possible, but I'd imagine if all the Macs are sitting in carts already, that might not be so easy to do.

I took the same basic script I had put together and came up with this, which you can run from a Mac that is on your network (can reach your JSS)
The basic idea is, you first need to output a csv file from your JSS in the following format

field 1: Mac Name
field 2: JSS ID

That's all the data you need for this. If you add additional fields beyond those, as long as the first 2 columns are in that order it should be OK.
Here's the thing though. The .csv file should be opened in an application like TextWrangler, and re-saved to make sure its using Unix line breaks, otherwise the loop process doesn't work in my experience. Here's a screen shot of the settings from the Save As window of TextWrangler, where I changed the Line breaks and the encoding to UTF-8 and saved it.

af4111e198a04acd9c84a034778cda4d

Save the script below with a name, like "bulk_delete_location.sh" or something, wherever you want, make sure its executable in Terminal:
chmod +x /path/to/bulk_delete_location.sh

Then you can run it like so:
/path/to/bulk_delete_location.sh /path/to/MacList.csv
where MacList.csv is the csv file you saved out of TextWrangler.

Here is the script. Make sure to fill in the ** sections with actual API username/password and JSS URL information.

#!/bin/bash

## Change these 3 variables to match your setup. API account must have API write privs
apiUser=" ***** "
apiPass=" ***** "
jssURL=" ***** "

csvFile="$1"

if [ -z "$csvFile" ]; then
    echo "No file was specified for the script. Type in a file path and name after the script name in Terminal and try again."
    exit 1
fi

if [[ -z "$apiUser" ]] || [[ -z "$apiPass" ]] || [[ -z "$jssURL" ]]; then
    echo "The API username or password or JSS URL were not specified in the script. Please add these details and try again."
    exit 1
fi

## Create the xml for upload via API
echo "<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<computer>
    <location>
        <username/>
        <real_name/>
        <email_address/>
        <position/>
        <phone/>
        <department/>
        <building/>
        <room/>
    </location>
</computer>" > "/tmp/blank_location.xml"

cat "$csvFile" | while read Mac; do
    MacName=$(echo "$Mac" | cut -d, -f1)
    MacID=$(echo "$Mac" | cut -d, -f2)
    curl -sfku "${apiUser}:${apiPass}" "${jssURL}/JSSResource/computers/id/$MacID" -T /tmp/blank_location.xml -X PUT
    if [ $? == 0 ]; then
        echo "${MacName}'s Location data was removed"
    else
        echo "Failed to remove ${MacName}'s Location data"
    fi
    sleep 0.5
done

I put a short sleep between each loop just so it hopefully doesn't do a DDOS on your JSS :) I strongly suggest you go slow and experiment with this by splitting it up into small groups first. Maybe 50-100 Macs at a time and see how it goes.

Use at your own risk. I haven't tested this on our live JSS and I don't plan to.

View solution in original post

9 REPLIES 9

mm2270
Legendary Contributor III

I'm not sure there's any way to do it in bulk, other than possibly with some 3rd party tools like the ruby jss add-on or something like that, but as I've only skimmed the surface of reading about that product, I'm only taking a guess.

I had put a script together that uses the JSS API to have each Mac auto clear out its Location information, but that's not going to help with a bulk change.
I would imagine you could use a script that takes an input file, like a csv with your Mac names and JSS IDs or some other identifier, like serial #, UDID, etc and loops over the list one by one and does an API PUT to each record to blank out the User & Location fields. It would work, but it would be kind of slow and may create a bit of traffic to your JSS.

Rayfield
New Contributor III

https://jamfnation.jamfsoftware.com/discussion.html?id=14404

Check the second post down, I replied with a script on that. You can have the script run on those computers that you need to clear all of the information out of.

Someone also modified it to use the serial number instead of the mac addresses, if you prefer to use it that way.

joshuasee
Contributor III

Are they passing form teacher to student hands untouched, with no reimaging or maintenance? If not, why not mass delete them from the JSS and reenroll them as part of maintenance?

Alternately, have you tried a once per computer policy to run a jamf recon command assigning empty values to the inventory info?

jamf recon -endUsername "" -realname "" -email "" -position "" -building "" -department "" -phone "" -room ""

Rayfield
New Contributor III

What I've seen during our normal reimaging/enrollment is that the username persists between enrollments.

But that jamf recon command should also work.

mm2270
Legendary Contributor III

Unfortunately the jamf recon with blanks does not work. At one time you could send a space instead of a null value to the recon and it worked, but once the JSS moved to version 9.x it stopped working. The only way in my testing I've been able to do it is with an API script, as mentioned on the linked thread. That was the script I was referring to, but as I mentioned, that won't do a bulk operation. It requires each Mac to run a policy to run the script to blank out its own record. If the Macs are still in use right now it may be possible, but I'd imagine if all the Macs are sitting in carts already, that might not be so easy to do.

I took the same basic script I had put together and came up with this, which you can run from a Mac that is on your network (can reach your JSS)
The basic idea is, you first need to output a csv file from your JSS in the following format

field 1: Mac Name
field 2: JSS ID

That's all the data you need for this. If you add additional fields beyond those, as long as the first 2 columns are in that order it should be OK.
Here's the thing though. The .csv file should be opened in an application like TextWrangler, and re-saved to make sure its using Unix line breaks, otherwise the loop process doesn't work in my experience. Here's a screen shot of the settings from the Save As window of TextWrangler, where I changed the Line breaks and the encoding to UTF-8 and saved it.

af4111e198a04acd9c84a034778cda4d

Save the script below with a name, like "bulk_delete_location.sh" or something, wherever you want, make sure its executable in Terminal:
chmod +x /path/to/bulk_delete_location.sh

Then you can run it like so:
/path/to/bulk_delete_location.sh /path/to/MacList.csv
where MacList.csv is the csv file you saved out of TextWrangler.

Here is the script. Make sure to fill in the ** sections with actual API username/password and JSS URL information.

#!/bin/bash

## Change these 3 variables to match your setup. API account must have API write privs
apiUser=" ***** "
apiPass=" ***** "
jssURL=" ***** "

csvFile="$1"

if [ -z "$csvFile" ]; then
    echo "No file was specified for the script. Type in a file path and name after the script name in Terminal and try again."
    exit 1
fi

if [[ -z "$apiUser" ]] || [[ -z "$apiPass" ]] || [[ -z "$jssURL" ]]; then
    echo "The API username or password or JSS URL were not specified in the script. Please add these details and try again."
    exit 1
fi

## Create the xml for upload via API
echo "<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<computer>
    <location>
        <username/>
        <real_name/>
        <email_address/>
        <position/>
        <phone/>
        <department/>
        <building/>
        <room/>
    </location>
</computer>" > "/tmp/blank_location.xml"

cat "$csvFile" | while read Mac; do
    MacName=$(echo "$Mac" | cut -d, -f1)
    MacID=$(echo "$Mac" | cut -d, -f2)
    curl -sfku "${apiUser}:${apiPass}" "${jssURL}/JSSResource/computers/id/$MacID" -T /tmp/blank_location.xml -X PUT
    if [ $? == 0 ]; then
        echo "${MacName}'s Location data was removed"
    else
        echo "Failed to remove ${MacName}'s Location data"
    fi
    sleep 0.5
done

I put a short sleep between each loop just so it hopefully doesn't do a DDOS on your JSS :) I strongly suggest you go slow and experiment with this by splitting it up into small groups first. Maybe 50-100 Macs at a time and see how it goes.

Use at your own risk. I haven't tested this on our live JSS and I don't plan to.

brandonusher
Contributor II

Why not just search up the devices in the JSS Interface, take Action on the group then Edit the Location information en-mass?

mm2270
Legendary Contributor III

Because as far as I know that doesn't work to remove the data. It works to update the Location data with info, but will not actually remove it. If you know otherwise, please share how you've done it, because I've never seen that actually work. Maybe I'm wrong though.. or I've just been doing it wrong when I've tried.

brandonusher
Contributor II

Ah, I see. Just took a second look and realized it doesn't allow taking out the Username etc. Only allows editing Department and Building.

Rayfield
New Contributor III

The easiest way (If the computers are checking in frequently) is to move them all to a smart group/static group and then have the script I linked above to run at check-in or start-up.

That way the next time someone uses one the information would be cleared out.

You can also put that script as part of the imaging process, We use Deploy Studio still for our imaging process and have it as part of the work flow to ensure every mac that gets newly imaged has that information cleared out for next use