Is there a way to mass change all MBP accounts labeled "Administrator" to "Robert"?

mrrobertbuss
Contributor

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

8 REPLIES 8

moriahitadmin
New Contributor III

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"

 

 

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?

 Screenshot 2023-12-19 at 11.42.47 AM.png

moriahitadmin
New Contributor III

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

 

moriahitadmin
New Contributor III

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

When trying to reply to you I am getting an error. Testing this reply.

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.

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.

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.