Prompt to rename computer at enrollment

JAMF_noob
New Contributor

I'm assuming the best way to do this is through a postflight script?

I'm enrolling several Macs into my new JSS - not imaging at this time. I'd like to get the computers name updated before they bind to Active Directory. Any suggestions / examples would be much appreciated!

10 REPLIES 10

calumhunter
Valued Contributor

/usr/sbin/scutil --set ComputerName InsertComputerNameHere
/usr/sbin/scutil --set LocalHostName InsertComputerNameHere
/usr/sbin/scutil --set HostName InsertComputerNameHere

ArielN
New Contributor

Hi calumhunter,

Can you send me the instruction on how to add this to my postflight script.

Thank You,
ArielN

donmontalvo
Esteemed Contributor III

We usually let DNS handle the HostName, so the AD and Network groups don't jump up and down on us.

--
https://donmontalvo.com

adamlalicker
New Contributor III

I made a script that fires off at first login.

#!/bin/bash
# capture user input name
while true
do
name=$(osascript -e 'Tell application "System Events" to display dialog "Please enter a name for your computer" default answer ""' -e 'text returned of result' 2>/dev/null)
    if [ $? -ne 0 ]     
    then # user cancel
        exit
    elif [ -z "$name" ]
    then # loop until input or cancel
        osascript -e 'Tell application "System Events" to display alert "Please enter a name or select Cancel!" as warning'
    else [ -n "$name" ] # user input
        break
    fi
done

sudo scutil --set ComputerName $name
sudo scutil --set LocalHostName $name
sudo scutil --set HostName $name
sudo /usr/local/bin/jamf recon

donmontalvo
Esteemed Contributor III

@adamlalicker We do something similar at Thin Provisioning time...mind if we steal some of your error handling? #tongueincheek

ComputerName=`/usr/bin/osascript <<EOT
tell application "System Events"
    activate
    display dialog "Enter Computer Name" default answer ""
    set ComputerName to (text returned of result)
end tell
EOT`
/bin/mkdir -p /Library/Company
echo $ComputerName > /Library/Company/thin-provision-computer-name.txt
sudo scutil --set HostName $ComputerName
sudo scutil --set LocalHostName $ComputerName
sudo scutil --set ComputerName $ComputerName
--
https://donmontalvo.com

applesupport-ne
New Contributor III

Question for anyone that can help. Is there a way to package this and make it part of the prestage enrollment package?

cbrewer
Valued Contributor II

Here is a script I wrote that you can run on the Enrollment trigger that will prompt for computer name during Setup Assistant. My workflow is to leave the machine on the Time Zone setup screen until the scripts run.

https://github.com/cwmcbrewster/Jamf_Scripts/blob/master/Computer_Enrollment_PromptForName.sh

tnielsen
Valued Contributor

Cbrewer, nice idea! Timing is funny. I just spent all day creating a Ldaemon that detects if the signed in user is local vs domain. If domain user detected it auto renames and rebinds the machine to ad.

I like your idea, though. May try it.

michael_sharpe
New Contributor II

Cbrewer, great idea! A question though...

You say your workflow is to leave the machine on Time Zone setup screen until the script runs. How long does this usually take? I've set this to kick off on the Enrollment complete trigger, as the first of many actions that the Enrollment complete trigger will perform.

I'm a little naive in understanding the logic behind the Enrollment complete trigger. Is enrollment actually complete before Setup Assistant begins? I've always assumed that enrollment completed after Setup Assistant but I have no reason to assume this other than empirical evidence while working with DEP, which we've just recently started to implement.

Thanks for any insights.

casafrancisco
New Contributor III

@adamlalicker I ended up using your script and it works well, if triggered by the user. Do you know of a way to do it or what to add to the script to allow the gui elements to appear when they run from root?

with other commands I have been using "sudo -u $3" so the logged in user is the one the command is running for. But how is this done in this case with applescript?