Have you tried instead of using scutil using the Jamf binary to set the computer name. I found it much easier to manage using sudo jamf setcomputername -name $newName. Here is my working script for the issue you are describing.
#!/bin/bash
username=$(/usr/bin/osascript<<END
tell application "System Events"
activate
set the answer to text returned of (display dialog "Please enter the computer name" default answer "" buttons {"Rename"} default button "Rename")
end tell
END)
echo $username
/usr/local/bin/jamf setcomputername -name $username
/usr/local/bin/jamf recon
That did it! Fantastic. Appreciate the help.
Have you tried instead of using scutil using the Jamf binary to set the computer name. I found it much easier to manage using sudo jamf setcomputername -name $newName. Here is my working script for the issue you are describing.
#!/bin/bash
username=$(/usr/bin/osascript<<END
tell application "System Events"
activate
set the answer to text returned of (display dialog "Please enter the computer name" default answer "" buttons {"Rename"} default button "Rename")
end tell
END)
echo $username
/usr/local/bin/jamf setcomputername -name $username
/usr/local/bin/jamf recon
Hi
This works Fantastic, just 1 q about this.
It added an icon on the desktop.
And it cant be remove
Got a quick fix for this?
Thanks
Hi
This works Fantastic, just 1 q about this.
It added an icon on the desktop.
And it cant be remove
Got a quick fix for this?
Thanks
I've got the same issue going on with the desktop icon after renaming. Trying to dig into it and find a solution. Anyone found anything on this yet?
echo "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<xsl:stylesheet version=\\"1.0\\" xmlns:xsl=\\"http://www.w3.org/1999/XSL/Transform\\">
<xsl:output method=\\"text\\"/>
<xsl:template match=\\"/\\">
<xsl:value-of select=\\"id\\"/>
</xsl:template>
</xsl:stylesheet>" > /private/var/tmp/stylesheet.xslt
curl -s -k \\
-H "Authorization: Bearer $jamfProApiToken" \\
-H "Content-type: application/xml" \\
-X PUT \\
-d "<computer><purchasing><purchasing_contact>$updatedmdmdeviceName</purchasing_contact></purchasing></computer>" \\
"${jamfProURL}/JSSResource/computers/id/$computerID"
echo "name change applied $updatedmdmdeviceName"
#curl -k \\
#-H "Authorization: Bearer $jamfProApiToken" \\
#-H "Content-type: application/xml" \\
#-X PUT \\
#-d "<computer><general><name>$updatedmdmdeviceName</name></general></computer>" \\
#"${jamfProURL}/JSSResource/computers/id/$computerID"
#echo "name change applied $updatedmdmdeviceName"
I have come to share some code, using api to update the MDM record will remove the need to have to do a recon, which in my experience really slows down a setup.
in my example I am currently testing the method by only changing the purchasing > purchasin_contact field for testing purposes, but the commented out section will change the name.
other fields could be used for testing, but this is one we don't use in our environment.
I am working on a greater script which will fix names incorrectly named, and will add prefixes and assigned usernames to the device, where the prefixes are stored within the assigned prestage vendor information, but other fields of the prestage could be used, including the prestage name if it was just the prefix.
the script also, checks for when a generic user is assigned, for shared devices, allowing for a admin user to receive a prompt to rename a device that is incorrectly named.
but as I was always frustrated with not being able to directly change the device name on the MDM, I thought I would share this here. and with the simple example, using the PUT command.
I have a mix of domain joined and Jamf connect devices atm, and some of which that are domain joined, I need to change onsite, and then rebind after a name change, so I have made allowances for that also in my code.
With over 2000 computer devices though, it will be a few weeks, of testing before I allow it to go live.
to get the device ID
#get device serial
strmacbookserial=$(ioreg -l | awk '/IOPlatformSerialNumber/ { print $4;}' | tr -d '"')
echo "strmacbookserial $strmacbookserial"
#get device info
# Get device information from Jamf API
deviceInfo=$( /usr/bin/curl \\
--header "accept: application/xml" \\
--request GET \\
--silent \\
--header "Authorization: Bearer $jamfProApiToken" \\
--url "$jamfProURL/JSSResource/computers/serialnumber/$strmacbookserial" )
#echo "deviceInfo $deviceInfo"
# Extract computerID info from API response
computerID=$( /usr/bin/xpath -e '/computer/general/id/text()' <<< "$deviceInfo" )
echo "computerID $computerID"
this will collect the ID of the device based on the serial number to use with the command above
this all depends on your ability to code with eh API and establish the Secure Token to run curl commands