Watch Demo×
×

See NinjaOne in action!

By submitting this form, I accept NinjaOne's privacy policy.

Script Guide: Automate macOS Install Date Retrieval for Efficient IT Asset Management

Key takeaways

  • The script fetches and optionally stores the macOS installation date, crucial for IT asset management.
  • It specifically targets Mac systems, using the stat command to determine the system’s first run date.
  • Integration with NinjaOne RMM allows for centralized management and storage of the install date in a custom field.
  • Automating the retrieval of installation dates streamlines asset management and security compliance.
  • This tool is particularly useful for planning hardware upgrades and maintaining security standards in older systems.
  • The script offers a more efficient alternative to manual checking or using disparate system management tools.
  • Regular usage of the script enhances inventory management and system health audits.
  • Proper configuration with tools like NinjaOne RMM is essential for the script’s effectiveness.
  • Overall, the script, in conjunction with NinjaOne, improves the management and security of macOS environments.

Introduction

Understanding a Mac’s installation date is a critical piece of information for IT professionals and Managed Service Providers (MSPs). This knowledge aids in tracking system age, managing updates, and ensuring security compliance. A Bash script like the one we’re discussing today streamlines this process, offering a practical solution for those in the field of IT management.

Background

In the dynamic world of IT, maintaining an inventory of system installation dates is paramount. This script, designed for macOS, fetches the install date of a system and optionally stores it in a custom field. For IT professionals and MSPs, having such a tool is invaluable for asset management and maintenance scheduling.

The script

#!/usr/bin/env bash
# Description: Fetches the install date and can store it in a custom field.
#
# Release Notes: Initial Release
# By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/terms-of-use.
# Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. 
# Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. 
# Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. 
# Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. 
# Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. 
# Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. 
# EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
#
# Usage: [Custom Field]
# <> are required
# [] are optional
#
# Example: installdate
#  Saves the install date to the customfield named installdate
#



function GetInstallDate() {
    stat -f "%SB" /var/db/.AppleSetupDone
}

function SetCustomField() {
    /Applications/NinjaRMMAgent/programdata/ninjarmm-cli "$@"
}

# When run directly without testing, the "__()" function does nothing.
test || __() { :; }

__ begin __

# Parameters
CustomField=${installDateCF:=$1}

InstallDate=$(GetInstallDate)

echo "${InstallDate}"

if [[ -n "${CustomField}" ]]; then
    SetCustomField set $CustomField $InstallDate
fi

__ end __

 

Access over 300+ scripts in the NinjaOne Dojo

Get Access

Detailed breakdown

The script works in several steps:

  • GetInstallDate function: Utilizes stat -f “%SB” /var/db/.AppleSetupDone to fetch the installation date of the Mac. This command retrieves the date when the setup was completed, which is essentially the system’s first run.
  • SetCustomField function: Calls /Applications/NinjaOne RMMAgent/programdata/NinjaOne RMM-cli with passed arguments. This is likely a custom command associated with NinjaOne RMM, a remote monitoring and management tool, to set a custom field value.
  • Test condition: test || __() { :; } is a placeholder for testing. In the actual run, this does nothing, effectively bypassing this block.
  • Execution flow: The script then initializes parameters, retrieves the install date using GetInstallDate, and prints it. If a custom field name is provided as an argument, it stores the date in this field using SetCustomField.

Potential use cases

Consider an IT manager at a medium-sized company. They use this script to periodically check and record the installation dates of all Macs in the organization. This data helps in planning hardware upgrades and ensuring that older systems remain compliant with the latest security standards.

Comparisons

Alternatives include manually checking the install date or using other system management tools. However, this script automates the process and integrates with NinjaOne RMM for centralized management, offering a more streamlined approach.

FAQs

  • How accurate is the installation date?
    • It’s the date when the initial setup of macOS was completed, generally accurate unless the system files were modified.
  • Can this script run on non-Mac systems?
    • No, it’s specifically designed for macOS.
  • Is NinjaOne RMM necessary for this script?
    • NinjaOne RMM is only needed if you want to store the date in a custom field using this specific script.

Implications

Knowing the installation date is crucial for maintaining system integrity and security. Older systems might be more vulnerable, and this script helps in identifying them for necessary updates or replacements.

Recommendations

  • Regularly run the script for up-to-date inventory management.
  • Integrate the script with regular system audits for a holistic view of system health.
  • Ensure that NinjaOne RMM or similar tools are properly configured to receive and store the data.

Final thoughts

Incorporating this script into the broader capabilities of NinjaOne can significantly enhance IT management efficiency. NinjaOne’s robust tools, combined with such custom scripts, create a powerful ecosystem for managing IT infrastructure, especially in environments with a significant number of macOS systems. The ability to swiftly and accurately determine installation dates is just one piece of the puzzle in ensuring optimal system performance and security.

Next Steps

Building an efficient and effective IT team requires a centralized solution that acts as your core service deliver tool. NinjaOne enables IT teams to monitor, manage, secure, and support all their devices, wherever they are, without the need for complex on-premises infrastructure.

Learn more about NinjaOne Remote Script Deployment, check out a live tour, or start your free trial of the NinjaOne platform.

Categories:

You might also like

NinjaOne Terms & Conditions

By clicking the “I Accept” button below, you indicate your acceptance of the following legal terms as well as our Terms of Use:

  • Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms.
  • Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party.
  • Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library belonging to or under the control of any other software provider.
  • Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations.
  • Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks.
  • Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script.
  • EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).