Skip to main content
Question

computer name script


JamfAdmin2
Forum|alt.badge.img+6

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 

6 replies

karthikeyan_mac
Forum|alt.badge.img+17

@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

 

 


pkleiber
Forum|alt.badge.img+9
  • Contributor
  • 60 replies
  • November 29, 2023
#!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 


AJPinto
Forum|alt.badge.img+26
  • Legendary Contributor
  • 2710 replies
  • November 29, 2023

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.


Forum|alt.badge.img+20
  • Valued Contributor
  • 732 replies
  • November 29, 2023

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.


pete_c
Forum|alt.badge.img+16
  • Honored Contributor
  • 251 replies
  • November 29, 2023
Matt11 wrote:

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


scottb
Forum|alt.badge.img+18
  • Valued Contributor
  • 1285 replies
  • November 29, 2023
pkleiber wrote:
#!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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings