#!/bin/bash
# Get the last user
lastUser=$(defaults read /Library/Preferences/com.apple.loginwindow lastUserName)
echo "Running recon for ${lastUser}..."
jamf recon -endUsername "${lastUser}"
If you want to manually add a domain suffix to lastUser:
lastUser="$(defaults read /Library/Preferences/com.apple.loginwindow lastUserName)@example.com"
#!/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
@robjschroeder This work great!!! Thank you so much!
@robjschroeder This work great!!! Thank you so much!
Awesome! I'm glad to see it worked for you!
@robjschroeder This work great!!! Thank you so much!
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.
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 ?
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 ?
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
```
#!/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.
```
#!/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.
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.
@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
@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
https://learn.jamf.com/bundle/jamf-pro-documentation-current/page/Computer_Inventory_Collection_Settings.html
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 ?