Friday - last edited Friday
Posting this for anyone experiencing an Office 365 login loop (Usually happens with Outlook). If reverting to legacy Outlook doesn't resolve your issue, run the keychain removal script below. It will restart the device. (The script is sourced from Scott Feit on the MacAdmins Slack channel and has resolved the issue multiple times for me)
#!/bin/bash
# Define the target directory
TARGET_DIR="$HOME/Library/Keychains"
# Function to log messages
log_message() {
echo "$(date +"%Y-%m-%d %H:%M:%S") - $1"
}
# Close the Keychain Access app
log_message "Closing Keychain Access application."
pkill -x "Keychain Access"
# Check if the target directory exists
if [ -d "$TARGET_DIR" ]; then
log_message "Starting cleanup of directories in $TARGET_DIR"
success_count=0
fail_count=0
# Find all directories within the target directory and delete them, logging each action
find "$TARGET_DIR" -type d -mindepth 1 -print0 | while IFS= read -r -d $'\0' dir; do
rm -rf "$dir"
if [ $? -eq 0 ]; then
log_message "Successfully deleted directory: $dir"
((success_count++))
else
log_message "Failed to delete directory: $dir"
((fail_count++))
fi
done
if [ $fail_count -eq 0 ]; then
log_message "Cleanup completed successfully. Running 'sudo jamf recon'."
# Run jamf recon
sudo jamf recon
log_message "Initiating forced restart with 15-second delay."
# Display a popup message with a 15-second timer before the restart
osascript -e 'tell app "System Events" to display dialog "Your computer will restart in 15 seconds." buttons {"OK"} default button 1 giving up after 15'
# Wait for 15 seconds before the restart
sleep 15
# Force a restart of the computer
sudo shutdown -r now "Script-initiated forced restart."
else
log_message "Cleanup completed with $fail_count failures. Restart aborted."
fi
else
log_message "Target directory does not exist. No actions were taken."
fi
Friday
@bwoods Is this error occurring when first enrolling a Mac and licensing is via an M365 account instead of a VL? If so, if you launch another office app (e.g. Word) before launching Outlook does Outlook then successfully create the account?
Saturday
Sometimes I do see this at enrollment and reverting Outlook fixes the issue. Other times I see it for users that have been enrolled for quite awhile. (Other apps are already signed in) Office Reset & reinstallation don't work for those cases. This script is what I use when the loop just won't seem to go away. Hope this helps someone out there. Thank you.
Saturday
Thanks for the extra details. It sounds like the problem you're seeing with Outlook is not the same one that's been biting me for the past several months.
Sunday
Outlook has been bad for use since September, but it got much worse in early October. We shut down our express route to Microsoft on Oct 1, and from then on, the standard Outlook no longer wants to show contents of the user inbox or shared mailboxes; for inboxes that do load, new email will come in, but any new email or replies are stuck in the Outbox; activations failing. Like you said, the only resolution for most of these is to switch to Legacy Outlook. I've got a ticket open with Microsoft and their 'suggestion' is for use to whitelist there entire list of URL's, and our security team is not having that.
19 hours ago
Thanks. Ran into this here and there. Will bookmark and use.