Category Filter

Script to Update OS in macOS devices

Apple releases OS updates periodically to fix bugs or strengthen the security of the released versions of the OS. Organizations prefer their devices to have the latest available OS. However, deploying OS updates can be a cumbersome task for the IT department of any organization because of the sheer number of devices. Hexnode provides three methods to update macOS devices; Update OS action, OS update via policies and by deploying scripts. This document contains the code snippet required to update macOS devices.

Disclaimer:

The Sample Scripts provided below are adapted from third-party Open-Source sites.

The above code uses a combination of commands and tools to update the OS to the latest version of macOS Big Sur available.

softwareupdate –l command is used to fetch the list of all available software updates.

grep “Big Sur” scans the list for available versions of macOS Big Sur. You may replace “Big Sur” in the above code with an OS version name suitable for your use case.

awk NR==1 filters the updated list to the latest version (row number 1).

cut –d ‘ ‘ -f 3- further processes the output to contain only the OS name identifier.

Finally, we pass the OS name identifier as an argument $getosupd with the softwareupdate command to install the specified OS version. The -i command installs the OS and the -R command can be added to automatically restart the system when the OS installation is complete.

To list all available OS versions for installation, use the following command –

The --list-full-installers command lists all available macOS installers. This command may not work as intended on older versions of macOS.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.