Posted on 11-14-2022 05:50 AM
Hi everyone
Can someone suggest me a good script to change my mac's name to "username-serialnumber" ?
Thanks
Solved! Go to Solution.
Posted on 11-14-2022 06:05 AM
@Philein You can scutil or jamf binary
#!/bin/bash
serialNumber=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
loggedinuser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
name=$loggedinuser-$serialNumber
scutil --set HostName $name
scutil --set LocalHostName $name
scutil --set ComputerName $name
or you can also use Jamf binary instead of scutil.
jamf setComputerName -name $name
Thanks
Posted on 11-14-2022 06:25 AM
I do this...
### Get serial number
serial=`/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Serial\ Number\ \(system\)/ {print $NF}'`
/usr/sbin/scutil --set ComputerName "${serial}"
/usr/sbin/scutil --set LocalHostName "${serial}"
/usr/sbin/scutil --set HostName "${serial}"
Posted on 11-14-2022 06:05 AM
@Philein You can scutil or jamf binary
#!/bin/bash
serialNumber=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
loggedinuser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
name=$loggedinuser-$serialNumber
scutil --set HostName $name
scutil --set LocalHostName $name
scutil --set ComputerName $name
or you can also use Jamf binary instead of scutil.
jamf setComputerName -name $name
Thanks
Posted on 11-14-2022 06:24 AM
Thanks. It works but it returns me this:
Script exit code: 0
Script result: SCPreferencesSetLocalHostName() failed: Invalid argument
Posted on 11-14-2022 06:25 AM
I do this...
### Get serial number
serial=`/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Serial\ Number\ \(system\)/ {print $NF}'`
/usr/sbin/scutil --set ComputerName "${serial}"
/usr/sbin/scutil --set LocalHostName "${serial}"
/usr/sbin/scutil --set HostName "${serial}"
Posted on 11-14-2022 07:21 PM
@Philein LocalHostName cannot have space dots. If your username has dot you may have to remove it.
loggedinuser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' | sed -e 's/\.//g' )
You can use the change the "loggedinuser" to strip the dots from the username.
Thanks
Posted on 11-14-2022 06:20 AM
you're also going to need to add:
/usr/local/jamf/bin/jamf recon
or a Maintenance to the policy to update Jamf
Posted on 11-14-2022 08:25 AM
This is a good time to point out that PII in a device name is generally not a good idea. Device names are broadcast in the clear on public networks, and personally identifiable information could be a security and/or safety risk. If your users are adults, you're probably ok, but I would definitely NOT recommend this for K12 devices.
Just my $0.0.2
Posted on 11-14-2022 08:40 AM
Thanks, this is a valid point.
12-09-2022 09:45 AM - edited 12-09-2022 09:46 AM
We have periods in the usernames, I use this script
#!/bin/sh
serial=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
currUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' | sed -e 's/\.//g' )
name=$currUser-$serial
/usr/sbin/scutil --set ComputerName $name
/usr/sbin/scutil --set HostName $name
/usr/sbin/scutil --set LocalHostName $name
exit 0