JAMF Connect Script

JamfAdmin2
New Contributor II

Hello everyone, 

 

I wanted to know if there is a script out there that can essentially have a user go through JAMF Connect and have their computer information populate into our jamf pro server with their macbook name changed already or have their user and location information filled in 

 

pretty much on my test mac where i am testing JAMF connect i go through the jamf connect window to login and on jamf pro my computer is there but it just says Macbook Air i would like for it to say jsmith-mac for example versus just Macbook Air 

 

Is there a script out there that can enable us to do that? 

6 REPLIES 6

curran
New Contributor III

The Jamf binary provides this ability. In Terminal, type Jamf help to see a list of commands. You can use setup methods like Setup Your Mac (SYM) where the information is input on first login. You can even have the information such as computer name and username automatically input.

For the Jamf binary, jamf -setComputerName will set the name of the computer. Use jamf help to see more which will show you how you can set the username.

For example with SYM. You can use Jamf Connect to create the users account, then auto populate the username field in SYM with the Jamf Connect logged in user. The computer name can be something like an auto append like xx-serialNumber and SYM uploads this to Jamf Pro using built in jamf binary commands.

The populated information in Jamf can then be used to auto populate Microsoft Office/Outlook for the end user.

Malcolm
Contributor II

is the MacBook being assigned to the same user?

I currently have a api script that will confirm the jamf connect logged in user is also the assigned user, I use this to recognise that jamf connect is correctly assigned and the end user assigned to the device is logged in
from here you could then mod the script to use their details to set the device name.

actually correction, I use it in combination of checking the logged in user and the assigned user are the same user. I was using it in addition to confirming jamf connect application was installed, rather than confirming the jamf connect logged in user matched the logged in and assigned user.
but there is a way to query the plist file of jamfconnect for other data such as the logged in jamf connect user.

I hit up support about this not too long ago, I will try and find the url for there information

JamfAdmin2
New Contributor II

Once we have fully tested with JAMF connect we will then release it to the whole organizations computers to all current users and future users who come work at our company 

AJPinto
Honored Contributor II

This would not be a function of JAMF Connect, but can be handled with a script deployed by JAMF. You can run a policy on enrollment to deploy a script to set the Macs Hostname.

 

I prefer to use Serial Numbers for the devices hostname for a few reasons.

  • Putting a users name in the hostname of the device reveals personally identifiable information (really bad)
  • Users names are not unique, you can run in to a situation where you have more then one jsmith-mac
  • If someone changes their name you will need to rerun policies, so it is not a set it and forget it.
  • If you must use jsmith-mac for ease of reference, use asset tags. They are not visible to the user, or to the network and can be used to find devices in JAMF and referenced with API.

This is the script I use. It can be adapted to use grab the name of the logged in user instead of the SN if you were so inclined, but I strongly recommend against putting peoples names in your device hostnames. 

#!/usr/bin/bash
#*=============================================================================
#* Script Name:
#* Created:
#* Author:
#*=============================================================================
#* Purpose: Changes Mac hostname to match SN if it does not already match
#*=============================================================================
 

#*=============================================================================
#* GLOBAL VARIABLES
#*=============================================================================
 
computerName=$(scutil --get ComputerName)
hostName=$(scutil --get HostName)
localHost=$(scutil --get LocalHostName)
serialNumber=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
serialNumberII=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | tr -d '"')
 
#*=============================================================================
#* FUNCTIONS
#*=============================================================================
 

#*=============================================================================
#* SCRIPT BODY
#*=============================================================================
userInfo
 
## Check & Update Computer Name
if [ "$computerName" == "$serialNumber" ]
then
    echo "Computer name matches serial number, $serialNumber"
else
    echo "Current Computer Name: $computerName"
    echo "Computer Name does not meet standards"
    echo "Changing Computer Name to match Serial Number"
    scutil --set ComputerName "$serialNumber"  
fi; $DIV2
 
## Check & Update Host Name
if [ "$hostName" == "$serialNumber" ]
then
    echo "Host Name matches serial number, $serialNumber"
else
    echo "Current Host Name: $hostName"
    echo "Host Name does not meet standards"
    echo "Changing Host Name to match Serial Number"
    scutil --set HostName "$serialNumber"
   
fi; $DIV2
 

## Check & Update Local Host
if [ "$localHost" == "$serialNumber" ]
then
    echo "Local Host matches serial number, $serialNumber"
else
    echo "Current Local Host: $localHost"
    echo "Local Host does not meet standards"
    echo "Changing Local Host to match Serial Number"
    scutil --set LocalHostName "$serialNumber"
   
fi; $DIV2
 

## Final Check
computerNameII=$(scutil --get ComputerName)
hostNameII=$(scutil --get HostName)
localHostII=$(scutil --get LocalHostName)
 
echo "Results:"; $DIV3
echo "Serial number: $serialNumber"
echo "Computer Name: $computerNameII"
echo "Host Name: $hostNameII"
echo "Local Host: $localHostII"
if [[ "$computerNameII" == "$serialNumber" ]] && [[ "$hostNameII" == "$serialNumber" ]] && [[ "$localHostII" == "$serialNumber" ]]
then
    echo "Computer Name satisfies naming standards"
    $DIV1; exit 0
else
    echo "Computer does not meet naming standars"
    echo "More troubleshooting will be necessary."
    $DIV1; exit 1
fi
 
#*=============================================================================
#* END OF SCRIPT
#*=============================================================================

 

Malcolm
Contributor II

This will give you password expiry

 

 

#!/bin/bash
 
#Get current signed in user
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name / { print $3 }' )
 
# Path to the preference with our current user's shortname
SigninExpiry=$( /usr/bin/defaults read /Users/$loggedInUser/Library/Preferences/com.jamf.connect.state.plist PasswordExpirationRemainingDays || echo "No record found")
 
echo "<result>$SigninExpiry</result>"
 
exit 0;

 

 

 

It can be used in a similar way for other data, which can be sen by simply running in terminal:

 

 

/usr/bin/defaults read ~/Library/Preferences/com.jamf.connect.state.plist 

 

 

 

UserShortName is probably what your after

combined with 

scutil --set LocalHostName $JCUserShortName

scutil --set ComputerName $JCUserShortName

scutil --set HostName $JCUserShortName

 

further reading:

https://learn.jamf.com/bundle/jamf-connect-documentation-current/page/State_Settings_and_User_Status...)

some example scripts they have are here: https://github.com/jamf/jamfconnect