Posted on 12-07-2021 09:29 AM
Hi I am looking for a script to replace the Username in the inventory section with the Extension Attribute of "Last User Logged In". In addition to add "@companyX.com" as a suffix to the user name. This would help me greatly in getting Asset inventory for my company via Azure. I am getting the Last User Logged In by Extension Attribute. So if the "Last User Logged In" is john.doe , take john.doe and add @companyX.com and fill the Username in the inventory section as john.doe@companyX.com. This would then poll Azure and I would get all the data I need. Still looking for a way to not manually update the username field when deploying a Mac to another user. My scripting skills are limited, apologies. Thanks,
JT
Solved! Go to Solution.
Posted on 12-13-2021 08:40 PM
#!/bin/bash
# Define domain suffix to add to username
domain="companyX.com"
# Get the last user of computer
lastUser=`defaults read /Library/Preferences/com.apple.loginwindow lastUserName`
if [ $lastUser != "" ]; then
username=$(echo "$lastUser"\@"$domain")
# Update Computer Inventory Record
jamf recon -endUsername $username
else
echo "No Logins, exiting..."
fi
Posted on 12-07-2021 09:51 AM
#!/bin/bash
# Get the last user
lastUser=$(defaults read /Library/Preferences/com.apple.loginwindow lastUserName)
echo "Running recon for ${lastUser}..."
jamf recon -endUsername "${lastUser}"
Posted on 12-07-2021 09:54 AM
If you want to manually add a domain suffix to lastUser:
lastUser="$(defaults read /Library/Preferences/com.apple.loginwindow lastUserName)@example.com"
Posted on 12-13-2021 08:40 PM
#!/bin/bash
# Define domain suffix to add to username
domain="companyX.com"
# Get the last user of computer
lastUser=`defaults read /Library/Preferences/com.apple.loginwindow lastUserName`
if [ $lastUser != "" ]; then
username=$(echo "$lastUser"\@"$domain")
# Update Computer Inventory Record
jamf recon -endUsername $username
else
echo "No Logins, exiting..."
fi
Posted on 01-19-2022 01:07 PM
@robjschroeder This work great!!! Thank you so much!
Posted on 01-19-2022 01:08 PM
Awesome! I'm glad to see it worked for you!
Posted on 07-27-2022 04:52 PM
this would of worked if our company email standard was, example JDoe@company.com, but our email standard name is Joe.Doe@company.com . Good thing the policy only went out to about 30 users. I'll just click on each computer and manually enter their email address, then hit the search icon and it will find them and populate, their name, email, department, etc.
Posted on 08-01-2023 05:47 AM
Hi
I need the help for the above script.The users are in Azure and need to update the last login user automatically on daily basis in Asset Inventory.I am new to Jamf Pro.Can anyone help me whether we need to put the above shell script to be run in all the user machine and then this will update it for the Asset inventory ?
Posted on 08-01-2023 06:28 AM
Hey @Lakshmana ! You would need to run this script with a policy once per day to populate the user and location username with the logged in user. You would also need to make sure you are collecting ldap information on your computers. That setting is in Computer Management > Inventory Collection
Posted on 08-01-2023 10:41 PM
```
#!/bin/bash
# Define domain suffix to add to username
domain="domain.com"
# Get the last user of computer
lastUser=$(defaults read /Library/Preferences/com.apple.loginwindow lastUserName)
if [ "$lastUser" != "" ]; then
# Extract the username without the domain suffix
username=$(echo "$lastUser" | cut -d "@" -f1)
# Add domain suffix to create the email address
email="$username"@"$domain"
# Update Computer Inventory Record
sudo jamf recon -endUsername "$username"
# Set the email address for the user
sudo jamf recon -email "$email"
else
echo "No Logins, exiting..."
fi
```
I am trying this method to get the last username information.But the username information is not always correct.Example)firstname.last@domain.com is the email id means i am getting this firstname.last as the username but for some users we have username@domain.com this becomes issue for me.
Example)User who logged in FirstnameLast is shown here because of this @domain.com is having error for me.
Issue 1)We have the email like this format for some users(firstname.letter@domain.com)
Issue 2)We have other emails like in this format for some users(username@domain.com)
Do we have any other way to rewrite this script validate the username information with the Azure ?
I also in need to get the Full Name and Position of the user information into the Jamf if possible.
Posted on 08-02-2023 05:53 AM
Do you have Azure AD connected via Cloud IdP in Jamf? You’ll also need the setting to collect LDAP data in your Computer Inventory Collection. But provided you have those two set up, it should pull in the users details into the computer inventory record after recon, provided there is a username in the record.
08-02-2023 05:58 AM - edited 08-02-2023 06:03 AM
@robjschroeder Yes I have connected my Azure AD via Cloud IdP in Jamf.How to do the settings with the LDAP data ?
Azure does not support LDAP here as far as I know.I have the users sync in the Google G-Suite which have LDAP here
Posted on 08-02-2023 06:03 AM
Posted on 08-02-2023 06:24 AM
I need one more help here.The users profile in the mac machine is not same as username of their email id.If we change it through a shell script that will create a new folder.how to make the changes in backend without making the data loss for the user folder in any case if its possible to do so ?