Posted on 12-18-2023 04:42 PM
I would like to change the current user account name from "Administrator" to "Robert" in one mass command to all MBP's (preferably silently in the background). I think a config profile could do this but not sure how.
JAMF PRO 11.1
Posted on 12-18-2023 05:17 PM
Script would do better.
sudo dscl . -change "/Users/Administrator" RecordName "Administrator" "Robert"
sudo mv "/Users/Administrator" "/Users/Robert"
sudo dscl . -change "/Users/Robert" NFSHomeDirectory "/Users/Administrator" "/Users/Robert"
sudo dseditgroup -o edit -u "Roebrt" -p -a "$Robert" -t user admin
You can also add to check mechanism
if id "Administrator" &>/dev/null; then
===code here===
fi
also
if id "Robert" &>/dev/null; then
echo "account already exist so you can delete if want to"
sudo dscl . -delete "/Users/Robert"
Posted on 12-19-2023 12:54 PM
1. I changed the misspelling of my name to Robert
sudo dseditgroup -o edit -u "Roebrt" -p -a "$Robert" -t user admin
2. Running sufo jamf policy I can see the script is trying to run. After waiting an hour it still won't run. The policy is called BobbyB. Any ideas why it won't execute?
Posted on 12-19-2023 02:45 PM
yea sorry my bad, change last line (sudo dseditgroup -o edit -u "Robert" -p -a "$Robert" -t user admin )with the one below. -p parameter requires user password
/usr/bin/dscl . -append /Groups/admin GroupMembership Robert
Posted on 12-19-2023 02:54 PM
lets tidy up
#!/bin/bash
#Variables
current_admin="Administrator"
new_admin="Robert"
if id "$new_admin" &>/dev/null; then
echo "Username already exist."
exit 1
else if id "$current_admin" &>/dev/null; then
sudo dscl . -change "/Users/$current_admin" RecordName "$current_admin" "$new_admin"
sudo mv "/Users/$current_admin" "/Users/$new_admin"
sudo dscl . -change "/Users/$new_admin" NFSHomeDirectory "/Users/$current_admin" "/Users/$new_admin"
sudo /usr/bin/dscl . -append /Groups/admin GroupMembership "$new_admin"
echo "Admin username is changed."
exit 0
else
echo "Coult not find admin account"
exit 1
fi
fi
Posted on 12-19-2023 05:48 PM
When trying to reply to you I am getting an error. Testing this reply.
Posted on 12-19-2023 05:58 PM
This is the error I get when trying to add the log from sudo jamf policy
Your post has been changed because invalid HTML was found in the message body. The invalid HTML has been removed. Please review the message and submit the message when you are satisfied.
Posted on 12-19-2023 05:59 PM
Executing Policy Change Administrator name to BobbyB 3
Running script BobbyB 3...
Script exit code: 0
Script result: <main> attribute status: eDSAttributeNotFound
<dscl_cmd> DS Error: -14134 (eDSAttributeNotFound)
mv: rename /Users/Administrator to /Users/Robert/Administrator: Operation not permitted
<dscl_cmd> DS Error: -14009 (eDSUnknownNodeName)
change: Invalid Path
Admin username is changed.
Posted on 12-19-2023 06:01 PM
Finally found a way to get the error message to you. So we are close and the name was not changed as it stated. Not sure what is causing the error.