Get Computers assigned to user

dgkanavias
New Contributor

Hi guys ,

I would like to get all the computers which are assigned to the current login user ( via command ) .

Do you have any idea , if this is possible ?

7 REPLIES 7

davidacland
Honored Contributor II

Hi, you use the jamf recon command. Here's a guide from the Mac mule https://macmule.com/2014/05/04/submit-user-information-from-ad-into-the-jss-at-login-v2/

dgkanavias
New Contributor

Hi , if i am not wrong that command is used in order to update the JSS and not get information for specific user .

mm2270
Legendary Contributor III

You might need to clarify exactly what it is you're looking for. Personally I'm not sure I understand what you mean by computers assigned to user.
If you happen to be capturing the user information on your Macs in the User & Location fields, then you can search for a username in the JSS and pull up any Macs that have that name assigned to them. Is that what you mean?

dgkanavias
New Contributor

Yes , i want to do that via script and not manually .

jjones
Contributor II

Here is the script we use to grab and set the user field in Casper, we also tied our AD information in to set additional fields casper offers as you see in the script.

Background on our AD, we have our's setup as firstinitial lastname so i.e jjones for me.

#!/bin/sh

loggedInUser=""
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

userRealName=`dscl . -read /Users/$loggedInUser | grep RealName: | cut -c11-`

userPosition=`dscl . -read /Users/$loggedInUser | grep JobTitle: | cut -c 11-`

userDepartment=`dscl . -read /Users/$loggedInUser | grep "Company:" | cut -c 10-`

sudo jamf recon -endUsername "$loggedInUser" -realname "$userRealName" -position "$userPosition" -department "$userDepartment"

mostlikelee
Contributor

You all might want to vote this up to auto-set the JSS assigned user field based on usage:

https://jamfnation.jamfsoftware.com/featureRequest.html?id=4304

apizz
Valued Contributor

Sounds like the command you're looking for is below (got from this discussion - https://jamfnation.jamfsoftware.com/discussion.html?id=17402):

FYI, the discussion where this comes from has an error in the syntax of the command: it lists -endUserName rather than -endUsername

jamf recon -endUsername $(defaults read /Library/Preferences/com.apple.loginwindow lastUserName)

This goes through recon and reports the last user as the user assigned to the computer. We ended up creating two separate inventory update policies, one for computers not assigned to any one individual (cart and lab computers) and one for computers assigned to individuals.