Way to clear the User and Location fields

ryan_macutay
New Contributor II

Hi There!

Does anyone know of a way to clear the fields in the "User and Location" tab of the JSS. I know that I can use the 'jamf recon' command to enter new data into those fields but I'd like a way to quickly make those fields empty using, preferably through the jamf recon command (so I can place it in a shell script) or during the imaging process.

Any ideas?

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

I think, not certain, that the act of re-enrolling a Mac, for example at the end of a re-image, blanks those values out automatically. Again, I'm not completely certain. If you find it isn't doing that, or you just want a different way to blank them out programmatically. there are a couple of ways.

One, just use the jamf recon but place empty spaces into each location field that you can specify. Not that they have to be spaces, not just an empty string or for some reason the JSS ignores them.

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

Two, have your script generate and upload an xml with null values using the Casper Suite API

#!/bin/sh

## Change these 3 variables to match your setup. API account must have API write privs
apiUser="apiusername"
apiPass="apiPassword"
jssURL="https://your.jss.address:8443"

## get this Mac's MAC address
MAC=$( networksetup -getmacaddress en0 | awk '{print $3}' | sed 's/:/./g' )

## 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"

## Now upload the xml file
curl -s -k -u "${apiUser}:${apiPass}" "${jssURL}/JSSResource/computers/macaddress/$MAC" -T /tmp/blank_location.xml -X PUT

One thing to note. With either method, if you're setting some location information based on Network Segments, those settings will remain, since they come from a different set of criteria.

View solution in original post

8 REPLIES 8

mm2270
Legendary Contributor III

I think, not certain, that the act of re-enrolling a Mac, for example at the end of a re-image, blanks those values out automatically. Again, I'm not completely certain. If you find it isn't doing that, or you just want a different way to blank them out programmatically. there are a couple of ways.

One, just use the jamf recon but place empty spaces into each location field that you can specify. Not that they have to be spaces, not just an empty string or for some reason the JSS ignores them.

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

Two, have your script generate and upload an xml with null values using the Casper Suite API

#!/bin/sh

## Change these 3 variables to match your setup. API account must have API write privs
apiUser="apiusername"
apiPass="apiPassword"
jssURL="https://your.jss.address:8443"

## get this Mac's MAC address
MAC=$( networksetup -getmacaddress en0 | awk '{print $3}' | sed 's/:/./g' )

## 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"

## Now upload the xml file
curl -s -k -u "${apiUser}:${apiPass}" "${jssURL}/JSSResource/computers/macaddress/$MAC" -T /tmp/blank_location.xml -X PUT

One thing to note. With either method, if you're setting some location information based on Network Segments, those settings will remain, since they come from a different set of criteria.

ryan_macutay
New Contributor II

Thanks for your help! Unfortunately, re-imaging doesn't clear the fields. I also tried your tip with spaces and that doesn't do it either. I was hoping to stay away from using the Casper API (mostly because it's still foreign to me) but it looks like there isn't another way to do this...

bentoms
Release Candidate Programs Tester

@ryan.macutay, I have a script on my blog that shows how to query AD & submit user information from before we could do this in the JSS.

Have a look at the recon flags, you should be able to write a script that populates the fields with any or no data using those flags.

http://macmule.com/2012/05/16/submit-user-information-from-ad-into-the-jss-at-login/

ryan_macutay
New Contributor II

@bentoms Thanks for the link. I tried the flags but it seems the only way they take effect is if I they have values. Adding blank spaces as values don't seem to clear the fields. It would be nice if it did though...

mm2270
Legendary Contributor III

@ryan.macutay - what JSS version are you on? I'm wondering if this is new behavior in the 9 series, because in my tests on our 8.73 JSS, adding a space, not a null value, in the recon flags blanked out the values back in computer record in the JSS.

If its not doing that anymore under 9.x, then your only real way may be to go the API route. Its not that hard actually. The script I posted above can work on any Mac currently enrolled in your JSS, since it pulls the Mac's MAC address and uses that for the API PUT command. You shouldn't need to edit anything in that script for it to work other than the API username, API password and JSS URL values. Oh, and of course you need at least one account (the one you enter in the script variables) that has API privilege, to write to the server.

ryan_macutay
New Contributor II

Well, after speaking to my Jamf rep, it appears that clearing the fields through the recon command doesn't work in casper 9.x so I went ahead and used @mm2270's script. I did decide to change it a bit and use serial numbers instead of MAC address though. Thanks @mm2270 for your help!

Sean_Ginn
New Contributor II

Would you mind posting the update script?

ryan_macutay
New Contributor II

@Sean_Ginn Here's the modified script. Everything is the same as mm2270's script except it uses serial numbers instead.

#!/bin/sh

## Change these 3 variables to match your setup. API account must have API write privs
apiUser="apiusername"
apiPass="apiPassword"
jssURL="https://your.jss.address:8443"

## get this Mac's Serial number
SNUM=$(ioreg -l | grep IOPlatformSerialNumber | awk '{print $4}'| sed 's/"//g')

## 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"

## Now upload the xml file
curl -s -k -u "${apiUser}:${apiPass}" "${jssURL}/JSSResource/computers/serialnumber/$SNUM" -T /tmp/blank_location.xml -X PUT