Skip to main content

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 

@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

 

 


#!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 

Getting the current user in macOS 


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.


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.


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.


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.)


#!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 

Getting the current user in macOS 


One tiny typo: 😁

 

#!bin/sh#!/bin/sh

 

 


Reply