I need help with a script which can pull the first and last name of a user from the device and set this as their computer name, which is then reflected in Jamf Pro.
I've had some success with the below script taken from another thread, but this only works for users with one first and last name. When someone with a middle name adds it to their account name, it doesn't add the surname, rather the first two names.
#!/bin/sh
#gets current logged in user
getUser=$(ls -l /dev/console | awk '{ print $3 }')
#gets named
firstName=$(finger -s $getUser | head -2 | tail -n 1 | awk '{print tolower($2)}')
lastName=$(finger -s $getUser | head -2 | tail -n 1 | awk '{print tolower($3)}')
computerName=$firstName$lastName
#set all the name in all the places
scutil --set ComputerName "$computerName"
scutil --set LocalHostName "$computerName"
scutil --set HostName "$computerName"
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder && sudo jamf recon
Does anyone have a current script which does this reliably or something very similar?