Posted on 11-28-2023 01:21 PM
Hello Everyone,
I am looking for a script out there that i can use in a jamf policy to have a user login and have the computer name auto update in jamf so when the user logs in i can locate the computer in jamf and her name will appear for her computer name
Posted on 11-28-2023 08:42 PM
@JamfAdmin2 Do you need to set the computer name as the current logged in username and update Jamf inventory? You can use the below script at login to set username as computername.
Thanks.
#!/bin/bash
userName=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
scutil --set HostName $userName
scutil --set LocalHostName $userName
scutil --set ComputerName $userName
Posted on 11-29-2023 12:58 AM
#!bin/sh
currentUser=$( /usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk '/Name :/ && ! /loginwindow/ { print $3 }' )
echo "Logged in User: $currentUser"
echo "Setting Username as ComputerName"
scutil --set ComputerName "$currentUser"
scutil --set HostName "$currentUser"
scutil --set LocalHostName "$currentUser"
dscacheutil -flushcache
jamf recon
Source for the method from @arminBriegel
Posted on 11-29-2023 12:27 PM
One tiny typo: 😁
#!bin/sh
#!/bin/sh
Posted on 11-29-2023 05:16 AM
One word of warning. Computers hostnames are publicly visible. A person's name is Persinally Identifiable Information. You don't want to open broadcast PII. If you want to use someone's name for easy tracking, use an Asset Tag.
Posted on 11-29-2023 06:15 AM
Would highly suggest against doing this security wise. If anything just use the serial numbers and then use an extension attributes to gather the last logged in user.
Posted on 11-29-2023 07:53 AM
This is absolutely the better course of action. If reading the membership of a Smart Group and only seeing computer names is your original issue, create a new Advanced Search for computer group membership, then edit the Display options as necessary. (Yes, it's an extra step, but gets you much more tailored results displayed.)