Check AppleCare Warranty Status

This script checks the warranty status of Apple devices by reading the local warranty information stored by macOS. It retrieves the coverage end date and displays it in a user-friendly format. The script is designed to work with Intune-managed macOS devices as a custom attribute.

Monitoring
131 views69 downloadsVersion 1.0By Ugur Koc
View on GitHub

// QUALITY CHECKS

Validation status

Quality checks

All checks pass
  • ShellCheckPass

Tests run automatically on every change. What does each check mean?

// TESTED PLATFORMS

Verified runtimes

macOS

// CHANGELOG

Version history

  1. Entry · 01

    1.0 - Initial release

// CODE

Source

check-applecare-warranty-status.sh
#!/bin/bash

# TITLE: Check AppleCare Warranty Status
# SYNOPSIS: Checks Apple warranty and AppleCare status on macOS devices
# DESCRIPTION: This script checks the warranty status of Apple devices by reading the local
#              warranty information stored by macOS. It retrieves the coverage end date
#              and displays it in a user-friendly format. The script is designed to work
#              with Intune-managed macOS devices as a custom attribute.
# TAGS: Monitoring,Device
# PLATFORM: macOS
# MIN_OS_VERSION: 10.15
# AUTHOR: Ugur Koc
# VERSION: 1.0
# LASTUPDATE: 2025-06-02
# CHANGELOG:
#   1.0 - Initial release
#
# EXAMPLE:
#   ./check-applecare-warranty-status.sh
#   Checks the warranty status and outputs coverage expiration dates
#
# NOTES:
#   - Script reads warranty information from macOS system files
#   - No external dependencies required
#   - Designed for Intune custom attributes (single line output)
#   - Works when run as root or user context
#   - For more scripts and guides, visit: IntuneMacAdmins.com
#   - Source: https://community.jamf.com/t5/jamf-pro/collecting-warranty-status/m-p/298357#M263560

# ============================================================================
# VARIABLES AND INITIALIZATION
# ============================================================================

# Function to check warranty for a specific user
check_user_warranty() {
    local user_home="$1"
    local warrantyDir="$user_home/Library/Application Support/com.apple.NewDeviceOutreach"
    
    # Check if the directory exists
    if [ ! -d "$warrantyDir" ]; then
        return 1
    fi
    
    # Find warranty files
    local warrantyFiles
    warrantyFiles=$(find "$warrantyDir" -maxdepth 1 -name "*_Warranty*" -type f 2>/dev/null)
    
    if [ -z "$warrantyFiles" ]; then
        return 1
    fi
    
    # Get the most recent warranty file
    local latestFile
    latestFile=$(echo "$warrantyFiles" | xargs ls -t 2>/dev/null | head -n1)
    
    if [ -z "$latestFile" ]; then
        return 1
    fi
    
    # Read the coverage end date
    local expires
    expires=$(defaults read "$latestFile" coverageEndDate 2>/dev/null || echo "")
    
    if [ -n "$expires" ]; then
        # Convert epoch to ISO-8601 format for better compatibility
        local ACexpires
        ACexpires=$(date -r "$expires" '+%Y-%m-%d' 2>/dev/null || echo "")
        
        if [ -n "$ACexpires" ]; then
            # Check if warranty has expired
            local currentDate
            currentDate=$(date +%s)
            if [ "$expires" -lt "$currentDate" ]; then
                echo "Expired: $ACexpires"
            else
                echo "Expires: $ACexpires"
            fi
            return 0
        fi
    fi
    
    return 1
}

# ============================================================================
# MAIN SCRIPT LOGIC
# ============================================================================

# Try to get warranty information
# First, try the current console user
loggedInUser=$(stat -f "%Su" /dev/console 2>/dev/null)

if [ -n "$loggedInUser" ] && [ "$loggedInUser" != "root" ] && [ "$loggedInUser" != "_windowserver" ]; then
    # Check logged in user's warranty
    userHome=$(dscl . -read /Users/"$loggedInUser" NFSHomeDirectory 2>/dev/null | awk '{print $2}')
    if [ -n "$userHome" ] && [ -d "$userHome" ]; then
        result=$(check_user_warranty "$userHome")
        if [ -n "$result" ]; then
            echo "$result"
            exit 0
        fi
    fi
fi

# If no console user or warranty not found, check all user directories
for userHome in /Users/*; do
    # Skip system directories
    if [[ "$userHome" == "/Users/Shared" ]] || [[ "$userHome" == "/Users/Guest" ]]; then
        continue
    fi
    
    if [ -d "$userHome" ]; then
        result=$(check_user_warranty "$userHome")
        if [ -n "$result" ]; then
            echo "$result"
            exit 0
        fi
    fi
done

# If we get here, no warranty information was found
echo "No warranty information"
exit 0

// NOTES

Author notes

- Script reads warranty information from macOS system files - No external dependencies required - Designed for Intune custom attributes (single line output) - Works when run as root or user context - For more scripts and guides, visit: IntuneMacAdmins.com - Source: https://community.jamf.com/t5/jamf-pro/collecting-warranty-status/m-p/298357#M263560

// RELATED

Picked by shared tags, category, and script type — nothing magic, just metadata overlap.

  1. Get Policy Drift Report

    This script takes a baseline folder created by backup-intune-configuration.ps1 and compares the tenant's current state against it: settings catalog policies (full setting bodies), classic device configuration profiles, and compliance policies. Policies are matched by object ID, and their configuration is compared as normalized JSON with volatile properties (timestamps, versions) removed. The report shows policies that were added, deleted, or modified since the baseline, making unreviewed configuration drift visible for change control.

    Monitoring
  2. Get Outdated iOS Devices Report

    Connects to Microsoft Graph and retrieves Intune-managed iOS devices, including their assigned user and last check-in date. Devices with an iOS major version lower than the older of the two supported major releases are exported to a timestamped CSV file. The supported major versions can be updated by parameter when Apple releases a new major version.

    Monitoring
  3. Apple Token Validity Checker

    This script connects to Microsoft Graph and retrieves all Apple Device Enrollment Program (DEP) tokens and Apple Push Notification Certificates configured in Intune. It checks their validity status, expiration dates, and sync status to help administrators proactively manage Apple Business Manager integrations. The script generates detailed reports in CSV format, highlighting tokens and certificates that are expired, expiring soon, or have sync issues.

    Monitoring