Setting computer name for PreStage Enrollment

New Contributor III

Is it possible to set the computer name during PreStage Enrollment? Ideally, I'd like it to be configurable, but just prefix-serial number would work.


Contributor III

We use Active Directory here, so standard naming the computer is important. I set a script to run at enrollment and modified @freddie.cox 's script from:

I also don't want the end user using the first local admin account that's created at enrollment time, so I have set the script to rename the first user account. The policy runs the script and then does a custom trigger that installs base software and reboots. At that point they can log in with their domain credentials and kick off file vault. The script is below:


ComputerName=`/usr/bin/osascript <<EOT
tell application "System Events" activate set ComputerName to text returned of (display dialog "Please Input Asset Tag Number" default answer "" with icon 2)
end tell

Is computer Desktop or Laptop

model=sysctl hw.model | cut -d ' ' -f2
if [[ $model == "MacBook" ]]
scutil --set HostName <COMPANYLAPTOPSTANDARD>$ComputerName
scutil --set LocalHostName <COMPANYLAPTOPSTANDARD>$ComputerName
scutil --set ComputerName <COMPANYLAPTOPSTANDARD>$ComputerName
scutil --set HostName <COMPANYDESKTOPSTANDARD>$ComputerName
scutil --set LocalHostName <COMPANYDESKTOPSTANDARD>$ComputerName
scutil --set ComputerName <COMPANYDESKTOPSTANDARD>$ComputerName

Change First User Account

shortname=/usr/bin/who | /usr/bin/awk '/console/{ print $1 }'
longname=dscl . read /Users/$shortname RealName | awk -F: '{print $NF}' | sed -e 's/^ *//;/^$/d'
if [[ $shortname == "<ADMINACCOUNT>" ]]
echo <ADMINACCOUNT> exists
dscl . change /Users/$shortname NFSHomeDirectory "/Users/$shortname" "/Users/<ADMINACCOUNT>"
dscl . change /Users/$shortname RealName "$longname" "<ADMIN ACCOUNT>"
dscl . change /Users/$shortname RecordName "$shortname" "<ADMINACCOUNT>"
mv /Users/$shortname /Users/<ADMINACCOUNT>


Anybody have a script to remove the first user created (perhaps all users in the Users directory since there will only be one initially)? I would like to include it in our policy to run after the user has logged out and completely remove the LDAP created user they set it up with. I cannot seem to locate a script that will remove the user (needs to be generic as everyone will be logging in with a different ID).


I am doing the same thing as you but running into a lot of issues but yet so close. I set up a script to run that requires the end user to type in their asset tag (similar to you). However, it seems that when I run my policy after they get enrolled the machine will not join the domain. I use the same AD binding I have in the policy using Casper Remote and it works fine. So I know the binding is working. Have you ran into this putting the Mac into AD after enrollment? Also, the policy is taking forever to actually run once the Mac is enrolled. Not sure why it doesn't do it automatically since I have it set up with a smart group that is supposed to populate using the enrollment method. It takes a long time for it to populate that group and then it starts running the policy. Ideas on how you are doing it? Are you having any of these issues?

Thanks. @daniel.behan

New Contributor III

Resurrecting this old post...

We are looking for a way to rename computers with a Pre-Stage and found this script.

We are not prompted for an asset tag, can any one assist?